I have a simple plot in matplotlib and I would like to increase the distance between the title and the plot (without using suptitle
because it does not work on the version I use on a server). How to do that ?
We can use the plt. subplots_adjust() method to change the space between Matplotlib subplots. The parameters wspace and hspace specify the space reserved between Matplotlib subplots.
To change the range of X and Y axes, we can use xlim() and ylim() methods.
With matplotlib 2.2+
, you can use the keyword argument pad
:
ax.set_title('Title', pad=20)
Adjust pad
until you're happy with the axis title position. The advantage of this method over using rcParams
is that it only changes this one axis title.
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.
You can just pass y
parameter into plt.suptitle
method:
plt.suptitle('Amazing Stats', size=16, y=1.12);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With