droid192
droid192

Reputation: 2242

Place title at the bottom of the figure of an axes?

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

enter image description here

so on increased figheight it moves away:

enter image description here

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.

Upvotes: 7

Views: 4185

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339430

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?

Upvotes: 9

Related Questions