New in matplotlib 3.4.0
Row titles can now be implemented as subfigure suptitles:
The new subfigure feature allows creating virtual figures within figures with localized artists (e.g., colorbars and suptitles) that only pertain to each subfigure.
See how to plot subfigures for further details.
How to reproduce OP’s reference figure:
-
Either
Figure.subfigures
(most straightforward)Create 3×1
fig.subfigures
where eachsubfig
gets its own 1×3subfig.subplots
andsubfig.suptitle
:fig = plt.figure(constrained_layout=True) fig.suptitle('Figure title') # create 3x1 subfigs subfigs = fig.subfigures(nrows=3, ncols=1) for row, subfig in enumerate(subfigs): subfig.suptitle(f'Subfigure title {row}') # create 1x3 subplots per subfig axs = subfig.subplots(nrows=1, ncols=3) for col, ax in enumerate(axs): ax.plot() ax.set_title(f'Plot title {col}')
-
Or
Figure.add_subfigure
(onto existingsubplots
)If you already have 3×1
plt.subplots
, thenadd_subfigure
into the underlyinggridspec
. Again eachsubfig
will get its own 1×3subfig.subplots
andsubfig.suptitle
:# create 3x1 subplots fig, axs = plt.subplots(nrows=3, ncols=1, constrained_layout=True) fig.suptitle('Figure title') # clear subplots for ax in axs: ax.remove() # add subfigure per subplot 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'Subfigure title {row}') # create 1x3 subplots per subfig axs = subfig.subplots(nrows=1, ncols=3) for col, ax in enumerate(axs): ax.plot() ax.set_title(f'Plot title {col}')
Output of either example (after some styling):