将标题放在轴图形的底部?

2024-09-27 09:30:03 发布

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

标题垂直移动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')

enter image description here

所以当它移走的时候

enter image description here

我也试过: axs.set_title("mytitle", fontsize=14, va='bottom', ha='center') 无需重新定位(停留在顶部)和fontdict表单,无需更改:

axs.set_title('my_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})

更多信息请访问text cmds.


Tags: text距离标题titlecenterwhitesetha
1条回答
网友
1楼 · 发布于 2024-09-27 09:30:03

您希望标题与xaxis保持指定的绝对坐标距离。因此,首先将其定位在y=0。然后你可以使用一些以点为单位的填充来移动它。你知道吗

ax.set_title("Hello Title", y=0, pad=-25, verticalalignment="top")

您可以在图形创建中使用constrained_layout=True,以便在调整大小时不裁剪标题。你知道吗

How to get constant distance between legend and axes even when the figure is resized?中提出了一个类似的关于将图例放置在轴下方的问题

相关问题 更多 >

    热门问题