the title is moved vertically by y
, yet if figheight changes the title is not at constant distance/padding to the xaxis:
fig, axs = plt.subplots(1,1, figsize=(15,2.5*1.5))
axs.set_title("mytitle", fontsize=14, y=-0.2, ha='center')
so on increased figheight it moves away:
also i tried : axs.set_title("mytitle", fontsize=14, va='bottom', ha='center')
without re-location (stays at top) and the fontdict-form, no change:
axs.set_title('my_title', fontdict={'fontsize': 20, 'verticalalignment': 'bottom', 'horizontalalignment': 'center'})
EDIT
titles are just texts which i use instead now, its modular:
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})
more at text cmds.
You want the title at a specified distance in absolute coordinates from the xaxis. Hence you first position it at y=0
. Then you can use some padding in units of points to shift it from there.
ax.set_title("Hello Title", y=0, pad=-25, verticalalignment="top")
You can use constrained_layout=True
in the figure creation to have the title not be cropped when resizing.
A similar question about positioning the legend below the axes has been asked in How to get constant distance between legend and axes even when the figure is resized?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.