Python Matplotlib Figure Title Overlaps Axes Label When Using Twiny

Python Matplotlib figure title overlaps axes label when using twiny

I'm not sure whether it is a new feature in later versions of matplotlib, but at least for 1.3.1, this is simply:

plt.title(figure_title, y=1.08)

This also works for plt.suptitle(), but not (yet) for plt.xlabel(), etc.

Turning figure or axes title off

You can use

ax.set_title("default title") # always set a default title
ax.title.set_visible(title) # set on or off

To toggle, you could do

ax.title.set_visible(not ax.title.get_visible())

Increase distance between title and plot in matplolib?

There doesn't seem to be a clean way to set this directly (but might be worth a feature request to add that), however the title is just a text artist, so you can reach in and change it.

#ax = plt.gca()
ttl = ax.title
ttl.set_position([.5, 1.05])
#plt.draw()

should do the trick. Tune the 1.05 to your liking.



Related Topics



Leave a reply



Submit