【发布时间】:2014-02-03 10:12:24
【问题描述】:
我在同一页面上绘制三个子图。我想在所有子图中画一条水平线。以下是我的代码和结果图:(您可以注意到我可以在其中一个图上获得水平线,但不是全部)
gs1 = gridspec.GridSpec(8, 2)
gs1.update(left=0.12, right=.94, wspace=0.12)
ax1 = plt.subplot(gs1[0:2, :])
ax2 = plt.subplot(gs1[3:5, :], sharey=ax1)
ax3 = plt.subplot(gs1[6:8, :], sharey=ax1)
ax1.scatter(theta_cord, density, c = 'r', marker= '1')
ax2.scatter(phi_cord, density, c = 'r', marker= '1')
ax3.scatter(r_cord, density, c = 'r', marker= '1')
ax1.set_xlabel('Theta (radians)')
ax1.set_ylabel('Galaxy count')
ax2.set_xlabel('Phi (radians)')
ax2.set_ylabel('Galaxy count')
ax3.set_xlabel('Distance (Mpc)')
ax3.set_ylabel('Galaxy count')
plt.ylim((0,0.004))
loc = plticker.MultipleLocator(base=0.001)
ax1.yaxis.set_major_locator(loc)
plt.axhline(y=0.002, xmin=0, xmax=1, hold=None)
plt.show()
这会生成以下内容:
再次,我希望我在最后一个子图中绘制的线也出现在前两个子图中。我该怎么做?
【问题讨论】:
-
一般来说,您的问题包含的不需要的细节(如坐标轴标签、实际数据)越少越好。最好是您的代码是可复制粘贴运行的。
标签: python matplotlib scatter-plot subplot line-plot