如果有多个子块包含次要y轴(使用twinx创建),如何在子块之间共享这些次要y轴?我希望它们以自动方式均匀缩放(所以以后不要手动设置y限制)。 对于主y轴,可以在调用子块时使用关键字shary。
下面的示例显示了我的尝试,但它未能共享两个子块的次y轴。我正在使用Matplotlib/Pylab:
ax = []
#create upper subplot
ax.append(subplot(211))
plot(rand(1) * rand(10),'r')
#create plot on secondary y-axis of upper subplot
ax.append(ax[0].twinx())
plot(10*rand(1) * rand(10),'b')
#create lower subplot and share y-axis with primary y-axis of upper subplot
ax.append(subplot(212, sharey = ax[0]))
plot(3*rand(1) * rand(10),'g')
#create plot on secondary y-axis of lower subplot
ax.append(ax[2].twinx())
#set twinxed axes as the current axes again,
#but now attempt to share the secondary y-axis
axes(ax[3], sharey = ax[1])
plot(10*rand(1) * rand(10),'y')
这让我觉得:
我使用axes()函数设置共享y轴的原因是twinx不接受sharey关键字。
我在Win7 x64上使用Python 3.2。Matplotlib版本是1.2.0rc2。
您可以像这样使用
Axes.get_shared_y_axes()
:这里我们只是把二次轴连接在一起。
希望能有所帮助。
相关问题 更多 >
编程相关推荐