如何创建这两个独立极坐标图的图形?

2024-10-05 14:27:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在同一个图形上创建两个单独的绘图作为子绘图。两个绘图都是极坐标的。我的尝试使他们在同一张图上作图

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()

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


Tags: 绘图plotnptablepipltthetapolar
2条回答

更面向对象的方法是:

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()

相当于谢尔多的答案,但显示了如何在matplotlib数字,轴和绘图

您需要如下:121表示1x2子地块网格上的第一个绘图,122表示1x2子地块网格上的第二个绘图

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

fig.show()

enter image description here

相关问题 更多 >