

.. _sphx_glr_gallery_userdemo_demo_gridspec04.py:


===============
Demo Gridspec04
===============





.. image:: /gallery/userdemo/images/sphx_glr_demo_gridspec04_001.png
    :align: center





.. code-block:: python

    import matplotlib.pyplot as plt
    import matplotlib.gridspec as gridspec


    def make_ticklabels_invisible(fig):
        for i, ax in enumerate(fig.axes):
            ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
            for tl in ax.get_xticklabels() + ax.get_yticklabels():
                tl.set_visible(False)


    # gridspec inside gridspec

    f = plt.figure()

    gs0 = gridspec.GridSpec(1, 2)

    gs00 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[0])

    ax1 = plt.Subplot(f, gs00[:-1, :])
    f.add_subplot(ax1)
    ax2 = plt.Subplot(f, gs00[-1, :-1])
    f.add_subplot(ax2)
    ax3 = plt.Subplot(f, gs00[-1, -1])
    f.add_subplot(ax3)


    gs01 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[1])

    ax4 = plt.Subplot(f, gs01[:, :-1])
    f.add_subplot(ax4)
    ax5 = plt.Subplot(f, gs01[:-1, -1])
    f.add_subplot(ax5)
    ax6 = plt.Subplot(f, gs01[-1, -1])
    f.add_subplot(ax6)

    plt.suptitle("GridSpec Inside GridSpec")
    make_ticklabels_invisible(f)

    plt.show()

**Total running time of the script:** ( 0 minutes  0.151 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

     :download:`Download Python source code: demo_gridspec04.py <demo_gridspec04.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: demo_gridspec04.ipynb <demo_gridspec04.ipynb>`

.. rst-class:: sphx-glr-signature

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
