繁体   English   中英

共享Y轴标签

[英]Share Y axis label

我有一个matplotlib图,它实际上是两个不同高度的子图,看起来像一个不相交的图。

在此处输入图片说明

我已经使用Gridspec做到了:

outer = gridspec.GridSpec(2, 1, height_ratios=[1,3])
gs1 = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec = outer[0])
ax1 = plt.subplot(gs1[0])
ax1.plot(no_rot,max_sd,'k*')
plt.ylabel('Y Axis Label')

gs2 = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec = outer[1])
ax2 = plt.subplot(gs2[0])
ax2.plot(no_rot,max_sd,'k*')
plt.xlabel('X Axis Label')
plt.ylabel('Y Axis Label')

现在,我只想拥有一个共享的集中式Y轴标签,但是我不确定该怎么做。

您可以尝试通过以下方式存储对标签的引用:

yaxis_label = plt.ylabel('My Y-axis')

然后以相对单位更改其位置,例如

yaxis_label.set_position((-0.05,0.5))

由于您有两个子图,因此可能需要在此处调整相对(x,y)使其正确定位。

或者,将子图明确地放置在图形中,并相对于图形坐标为y轴放置文本标签:

ax.text(0.05, 0.5, "My y-axis", transform=f.transFigure, rotation='vertical',
        verticalalignment='center')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM