gpt4 book ai didi

python - 共享Y轴标签

转载 作者:太空宇宙 更新时间:2023-11-03 17:32:39 26 4
gpt4 key购买 nike

我有一个 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 轴标签,但我不知道如何做到这一点。

最佳答案

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

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')

关于python - 共享Y轴标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31674125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com