.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_subplots_axes_and_figures_gridspec_and_subplots.py: ================================================== Combining two subplots using subplots and GridSpec ================================================== Sometimes we want to combine two subplots in an axes layout created with `~.Figure.subplots`. We can get the `~.gridspec.GridSpec` from the axes and then remove the covered axes and fill the gap with a new bigger axes. Here we create a layout with the bottom two axes in the last column combined. See also :doc:`/tutorials/intermediate/gridspec`. .. image:: /gallery/subplots_axes_and_figures/images/sphx_glr_gridspec_and_subplots_001.png :alt: gridspec and subplots :class: sphx-glr-single-img .. code-block:: default import matplotlib.pyplot as plt fig, axs = plt.subplots(ncols=3, nrows=3) gs = axs[1, 2].get_gridspec() # remove the underlying axes for ax in axs[1:, -1]: ax.remove() axbig = fig.add_subplot(gs[1:, -1]) axbig.annotate('Big Axes \nGridSpec[1:, -1]', (0.1, 0.5), xycoords='axes fraction', va='center') fig.tight_layout() plt.show() .. _sphx_glr_download_gallery_subplots_axes_and_figures_gridspec_and_subplots.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: gridspec_and_subplots.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gridspec_and_subplots.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_