如何将Axes图中的标题放在底部?

7

标题垂直移动 y,但如果figheight更改,则标题与x轴之间的距离/填充不是恒定的:

fig, axs = plt.subplots(1,1, figsize=(15,2.5*1.5))
axs.set_title("mytitle", fontsize=14, y=-0.2, ha='center')

进入图像描述

当figheight增加时,它会移动:

进入图像描述

我尝试了以下内容: axs.set_title("我的标题", fontsize=14, va='bottom', ha='center') 没有重新定位(在顶部停留)和fontdict-form,无变化:

axs.set_title('我的标题', fontdict={'fontsize': 20, 'verticalalignment': 'bottom', 'horizontalalignment': 'center'})

编辑

标题只是我现在使用的文本,它是模块化的:

axs.text(0.5,1,'some_title', va='bottom', ha='center', transform=axs.transAxes, color='k', fontsize=15, bbox={'facecolor':'white', 'edgecolor':'white', 'alpha':1, 'pad':10})

请查看文本命令以获取更多信息。

1个回答

9
您希望将标题相对于x轴的绝对坐标定位到指定距离。因此,您首先将其定位在y=0处。然后,您可以使用以点为单位的某些填充来从那里进行调整。
ax.set_title("Hello Title", y=0, pad=-25, verticalalignment="top")

在创建图形时可以使用 constrained_layout=True,使标题在调整大小时不被裁剪。

有关将图例定位于轴下方的类似问题已在此处提出。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接