首页 > 解决方案 > 如何创建这两个单独的极坐标图?

问题描述

我试图在同一个图上创建两个单独的图作为子图。两个地块都是极性的。我的尝试使他们绘制在同一张图上。

def GenerateTrigonometryTable(x): #Define Function
    A = np.arange (0,360,x) 
    B = np.sin(A*np.pi/180)  
    C = np.cos(A*np.pi/180)
    table = np.dstack(([A],[B],[C])) 
    return table 
Theta = (GenerateTrigonometryTable(5)[:,:,0]) 
STheta = (GenerateTrigonometryTable(5)[:,:,1])
CTheta = (GenerateTrigonometryTable(5)[:,:,2])

ax1 = plt.subplot(111, projection='polar')
ax1.plot(Theta.flatten(), STheta.flatten())
ax2 = plt.subplot(111, projection='polar')
ax2.plot(Theta.flatten(), CTheta.flatten())

fig.show()

这将它绘制在同一张图上,我需要它是两个独立图的图。

标签: pythonmatplotlib

解决方案


更面向对象的方法是:

fig = plt.figure()
ax1 = fig.add_subplot(121, projection='polar')
ax2 = fig.add_subplot(122, projection='polar')
ax1.plot(Theta.flatten(), STheta.flatten())
ax2.plot(Theta.flatten(), CTheta.flatten())

fig.show()

相当于Sheldore的回答,但显示了matplotlib中的图形、轴和图是如何表达的。


推荐阅读