Python 共享Y轴标签

Python 共享Y轴标签,python,matplotlib,Python,Matplotlib,我有一个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.ylab

我有一个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')