Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase distance between title and plot in matplolib? [duplicate]

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 ?

like image 477
Vincent Avatar asked May 07 '13 12:05

Vincent


People also ask

How do I increase space between title and plot in Matplotlib?

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.

How do you change the range of a Matplotlib plot?

To change the range of X and Y axes, we can use xlim() and ylim() methods.


3 Answers

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.

like image 74
apdnu Avatar answered Oct 24 '22 19:10

apdnu


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.

like image 57
tacaswell Avatar answered Oct 24 '22 18:10

tacaswell


You can just pass y parameter into plt.suptitle method:

plt.suptitle('Amazing Stats', size=16, y=1.12);      
like image 39
CanCeylan Avatar answered Oct 24 '22 20:10

CanCeylan