1

I have a figure that displays 12 subplots that are organised into 3 rows and 4 columns. I'd like each subplot to have it's own title and an centred title that is above each row.

The code below displays this for the first row. However, I'd like to generate the same suptitle for rows 2-3.

I have played around with plt.text but was wondering if there's a more efficient way to achieve this?

import matplotlib.pyplot as plt

fig, ((ax1, ax2, ax3, ax4),
      (ax5, ax6, ax7, ax8),
      (ax9, ax10, ax11, ax12)) = plt.subplots(3, 4)


ax1.set_title('Fig1', ha = 'center')
ax2.set_title('Fig2', ha = 'center')
ax3.set_title('Fig3', ha = 'center')
ax4.set_title('Fig4', ha = 'center')
ax5.set_title('Fig5', ha = 'center')
ax6.set_title('Fig6', ha = 'center')
ax7.set_title('Fig7', ha = 'center')
ax8.set_title('Fig8', ha = 'center')
ax9.set_title('Fig9', ha = 'center')
ax10.set_title('Fig10', ha = 'center')
ax11.set_title('Fig11', ha = 'center')
ax12.set_title('Fig12', ha = 'center')

plt.suptitle('Row 1')
#plt.suptitle('Row 2')

fig.tight_layout()
plt.draw()

Output:

As you can see, the suptitle is displayed for the first row but I'm unable to repeat that for the 2nd and 3rd rows. enter image description here

Community
  • 1
  • 1
  • 1
    If you had 3 columns instead of 3 rows, you could fake it with newlines in the titles. `plt.text` is probably a better option though. Can you show what you did with it? – Mad Physicist May 22 '18 at 04:38
  • Yeh, I've done that previously but the 4 figures in each row are associated with each other. I've used `plt.text` for the figure title and then `set_title` for the row. But as you alluded to, this only works if it was 4x3 –  May 22 '18 at 04:55
  • Can you show the code you wrote with `text` that should work just fine with any number of subplots – Mad Physicist May 22 '18 at 05:18

0 Answers0