Centered title inside of a subplot (matplotlib, pyplot)

17.6k views Asked by At

I have a 3x2 grid of equal sized plots. I use the command

plt.suptitle("Awesome title")     # (1)

to have a centered title above the 6 plots. I use the command

plt.title("Almost awesome title") # (2)

for a specific title above each subplot. Now the tricky part: I want a centered title between first and second row of subplots. After manipulating the position parameter of (2) to something like (1.1 , 1.0), I can not seem to get a properly/nicely formatted figure.

TL;DR: I want an additional plt.suptitle("Title") that be put as shown on picture below: (photoshopped)

Arbitrary plot to illustrate point of centered titles inside subplots

1

There are 1 answers

2
herrlich10 On BEST ANSWER

Just make some extra room between rows, and add text:

fig, axs = plt.subplots(2, 2)
plt.sca(axs[0,0])
plt.title('Sigmoid')
plt.sca(axs[0,1])
plt.title('ReLU')
plt.suptitle('Activation functions')

# Adjust vertical_spacing = 0.5 * axes_height
plt.subplots_adjust(hspace=0.5)

# Add text in figure coordinates
plt.figtext(0.5, 0.5, 'Effect of bias addition', ha='center', va='center')

enter image description here