.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/subplots_axes_and_figures/gridspec_multicolumn.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_subplots_axes_and_figures_gridspec_multicolumn.py: ======================================================= Using Gridspec to make multi-column/row subplot layouts ======================================================= `.GridSpec` is a flexible way to layout subplot grids. Here is an example with a 3x3 grid, and axes spanning all three columns, two columns, and two rows. .. GENERATED FROM PYTHON SOURCE LINES 11-35 .. image-sg:: /gallery/subplots_axes_and_figures/images/sphx_glr_gridspec_multicolumn_001.png :alt: GridSpec :srcset: /gallery/subplots_axes_and_figures/images/sphx_glr_gridspec_multicolumn_001.png, /gallery/subplots_axes_and_figures/images/sphx_glr_gridspec_multicolumn_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec def format_axes(fig): for i, ax in enumerate(fig.axes): ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center") ax.tick_params(labelbottom=False, labelleft=False) fig = plt.figure(layout="constrained") gs = GridSpec(3, 3, figure=fig) ax1 = fig.add_subplot(gs[0, :]) # identical to ax1 = plt.subplot(gs.new_subplotspec((0, 0), colspan=3)) ax2 = fig.add_subplot(gs[1, :-1]) ax3 = fig.add_subplot(gs[1:, -1]) ax4 = fig.add_subplot(gs[-1, 0]) ax5 = fig.add_subplot(gs[-1, -2]) fig.suptitle("GridSpec") format_axes(fig) plt.show() .. _sphx_glr_download_gallery_subplots_axes_and_figures_gridspec_multicolumn.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gridspec_multicolumn.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: gridspec_multicolumn.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_