Error:Matplotlib tight_layout() doesn't take into account figure suptitle

0 votes

If I add a subtitle to my matplotlib figure it gets overlaid by the subplot's titles. Does anybody know how to easily take care of that? I tried the tight_layout() function, but it only makes things worse.

Example:

import numpy as np
import matplotlib.pyplot as plt

f = np.random.random(100)
g = np.random.random(100)
fig = plt.figure()
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.tight_layout()
plt.show()
May 7 in Python by kartik
• 11,890 points
135 views

1 answer to this question.

0 votes

Hello,

You can simply adjust the coordinates of the suptitle text in the figure using the y argument in the call of suptitle:

import numpy as np
import matplotlib.pyplot as plt

f = np.random.random(100)
g = np.random.random(100)
fig = plt.figure()
fig.suptitle('Long Suptitle', y=1.05, 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.show()

Hope this works!!

Thank you!!

answered May 7 by Niroj
• 23,950 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

Error while converting a list into a numpy array

The only possible reason I could think ...READ MORE

answered Jun 13, 2019 in Python by Rhea
147 views
0 votes
1 answer

Error :on installing matplotlib

Hello @kartik, You had to install libfreetype6-dev and libpng-dev from the repositories. ...READ MORE

answered May 27 in Python by Niroj
• 23,950 points
149 views
+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
334 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 963 views
0 votes
0 answers
0 votes
1 answer

Error:Installation Issue with matplotlib Python

Hii @kartik, I assume you have installed the ...READ MORE

answered May 7 in Python by Niroj
• 23,950 points
116 views
0 votes
1 answer

Error:Pip install Matplotlib error with virtualenv

Hello @kartik, To generate graph in png format ...READ MORE

answered May 20 in Python by Niroj
• 23,950 points
52 views