I am trying to create a 3x3 subplots with a title and subtitle for each column and labeling each row. I was able to accomplish this with the code below.
cols = ['column 1', 'column 2', 'column 3']
rows = ['row 1', 'row 2', 'row 3']
fig, axs = plt.subplots(nrows=3, ncols=3, sharex=False, sharey='row')
for ax, col in zip(axs[0], cols):
ax.set_title(col, pad=15, y=1.5)
ax.text(0.5, 1.4, col, fontsize=12, ha='center')
pad = 25
for ax, row in zip(axs[:,0], rows):
ax.annotate(row, xy=(0, 0.5), xytext=(-ax.yaxis.labelpad - pad, 0),
xycoords=ax.yaxis.label, textcoords='offset points',
size='large', ha='right', va='center', rotation=90)
however the second I attempt to add any data, the ax.text(0.5, 1.4, col, fontsize=12, ha='center') text jumps down to the bottom of the graphs. An example with the issue, along with the code above.
cols = ['column 1', 'column 2', 'column 3']
rows = ['row 1', 'row 2', 'row 3']
fig, axs = plt.subplots(nrows=3, ncols=3, sharex=False, sharey='row')
for ax, col in zip(axs[0], cols):
ax.set_title(col, pad=15, y=1.5)
ax.text(0.5, 1.4, col, fontsize=12, ha='center')
pad = 25
for ax, row in zip(axs[:,0], rows):
ax.annotate(row, xy=(0, 0.5), xytext=(-ax.yaxis.labelpad - pad, 0),
xycoords=ax.yaxis.label, textcoords='offset points',
size='large', ha='right', va='center', rotation=90)
axs[0,0].bar([1, 2, 3, 4, 5], [3, 4, 5, 6, 10])
axs[1,2].bar([1, 2, 3, 4, 5], [3, 4, 5, 6, 10])

