Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centered title inside of a subplot (matplotlib, pyplot)

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

like image 375
Håkon T. Avatar asked Jan 06 '17 10:01

Håkon T.


1 Answers

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

like image 142
herrlich10 Avatar answered Sep 28 '22 13:09

herrlich10