如果您有多个包含辅助y轴的子图(使用twinx创建),那么如何在子图之间共享这些辅助y轴?我希望它们能够以自动方式均等地扩展(因此不能手动设置y限制).对于主y轴,可以通过在子图调用中使用关键字sharey来实现.
下面的示例显示了我的尝试,但它无法共享两个子图的辅助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) * …Run Code Online (Sandbox Code Playgroud)