I am trying to create a plot containing 8 subplots (4 rows and 2 columns). To do so, I have made this code that reads the x and y data and plots it in the following fashion:
fig, axs = plt.subplots(4, 2, figsize=(15,25))
y_labels = ['k0', 'k1']
for x in range(4):
for y in range(2):
axs[x, y].scatter([i[x] for i in X_vals], [i[y] for i in y_vals])
axs[x, y].set_xlabel('Loss')
axs[x, y].set_ylabel(y_labels[y])
This gives me the following result:
However, I want to add a title to all the rows (not the plots) in the following way(the titles in yellow text):
I found this image and some ways to do that here but I wasn't able to implement this for my use case and got an error. This is what I tried :
gridspec = axs[0].get_subplotspec().get_gridspec()
subfigs = [fig.add_subfigure(gs) for gs in gridspec]
for row, subfig in enumerate(subfigs):
subfig.suptitle(f'Subplot row title {row}')
which gave me the error : 'numpy.ndarray' object has no attribute 'get_subplotspec'
So I changed the code to :
gridspec = axs[0, 0].get_subplotspec().get_gridspec()
subfigs = [fig.add_subfigure(gs) for gs in gridspec]
for row, subfig in enumerate(subfigs):
subfig.suptitle(f'Subplot row title {row}')
but this returned the error : 'Figure' object has no attribute 'add_subfigure'