共享Y轴实验室

2024-06-28 11:43:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个matplotlib图,实际上是两个高度不同的子图,看起来像是一个不连贯的图。在

enter image description here

我用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轴标签,但我不知道怎么做。在


Tags: noplotpltsdgs1labelmaxouter
1条回答
网友
1楼 · 发布于 2024-06-28 11:43:09

您可以尝试使用以下内容存储对标签的引用:

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

然后改变它的相对位置

^{pr2}$

您可能需要调整相对(x,y)来正确定位它,因为您有两个子批次。在

或者,在地物中明确地放置子地块,并相对于地物坐标放置y轴的文本标签:

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

相关问题 更多 >