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()
这将它绘制在同一张图上,我需要它是两个独立图的图。
解决方案
更面向对象的方法是:
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中的图形、轴和图是如何表达的。
推荐阅读
- java - JavaFX 在不使用保留比率的情况下强制统一 ImageView 大小
- svg - SVG 图标的这个字符串是什么,我如何得到它?
- android-ndk - 将 AMediaExtractor 与位于媒体存储中的音频文件一起使用时,设置提取器数据源时出错,错误 -10002
- laravel - Laravel 5.6 - 如何仅在生产环境中执行预定的内核命令?
- java - 检查用户输入的字符串是否包含相同的字母
- javascript - 从开发工具中隐藏文件
- google-apps-script - 比较电子表格 1 和电子表格 2,然后发送电子邮件问题
- python - 如何向现有数据框添加新列并用另一列的部分数据填充它?
- sap-cloud-sdk - Java VDM 生成器不适用于带有 SAP Cloud SDK 版本 3.7.0 的 API_SALES_ORDER_SIMULATION_SRV
- ios - 如何在 Swift 中正确触发/调用“选择器”?