标题按 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')
因此随着高度的增加它会移开:
我也试过:
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.
最佳答案
您希望标题在距 x 轴绝对坐标的指定距离处。因此,您首先将其定位在 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? 中提出了关于将图例定位在轴下方的类似问题。
关于python - 将标题放在轴图的底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55239332/