Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Figure title (suptitle()) disappears if you specify figure size in Matplotlib

Take, for instance, this code sample:

import numpy as np
import matplotlib.pyplot as plt
f = np.random.random(100)
g = np.random.random(100)
fig = plt.figure(figsize=(15,15))
fig.suptitle('Long Suptitle', fontsize=24)
plt.subplot(121)
plt.plot(f)
plt.title('Very Long Title 1', fontsize=20)
plt.subplot(122)
plt.plot(g)
plt.title('Very Long Title 2', fontsize=20)
plt.subplots_adjust(top=0.85)
plt.show()

Running it shows two subplots with individual titles, but the overall figure title "Long Suptitle" is not visible.

However, if you remove figsize=(15,15), then the overall figure title becomes visible again.

Is it possible to keep the suptitle() text visible while modifying the size of the figure?

like image 708
Maxim Zaslavsky Avatar asked May 12 '13 01:05

Maxim Zaslavsky


People also ask

What is the difference between Suptitle and title?

The title is what people will remember to look up your book. The subtitle explains the book, telling them what they'll get out of reading it.

What is figure size in Matplotlib?

Syntax of matplotlib. It is an optional attribute, by default the figure has the dimensions as (6.4, 4.8). This is a standard plot where the attribute is not mentioned in the function. Normally each unit inch is of 80 x 80 pixels.


1 Answers

I had the same issue. I solved it by combining the plt.figure(figsize=(x,y)) and suptitle into one line:

plt.figure(figsize=(20,10)).suptitle("mytitle",fontsize=20)

(on matplotlib 2.2.2)

like image 67
solitarypotato Avatar answered Nov 15 '22 00:11

solitarypotato