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

2

8

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?

Levant answered 12/5, 2013 at 1:46 Comment(2)
For whatever it's worth, I can't reproduce your problems (The suptitle is visible and in a reasonable place for me). What version of matplotlib are you using? It's possible that this is a bug that's been fixed recently. Also, a workaround would be to pass in a different y position to suptitle. That shouldn't be necessary, though.Reft
Like @JoeKington I can't reproduce your error.Nephoscope
C
1

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)

Crossfade answered 3/4, 2019 at 0:26 Comment(0)
R
0

Try this:

fig = plt.figure(constrained_layout = True)
fig.set_figheight(15)
fig.set_figwidth(15)
Rennie answered 27/1, 2023 at 16:34 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Krp

© 2022 - 2024 — McMap. All rights reserved.