
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/userdemo/demo_gridspec06.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_userdemo_demo_gridspec06.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_userdemo_demo_gridspec06.py:


================
Nested GridSpecs
================

This example demonstrates the use of nested `.GridSpec`\s.

.. GENERATED FROM PYTHON SOURCE LINES 8-39



.. image-sg:: /gallery/userdemo/images/sphx_glr_demo_gridspec06_001.png
   :alt: demo gridspec06
   :srcset: /gallery/userdemo/images/sphx_glr_demo_gridspec06_001.png, /gallery/userdemo/images/sphx_glr_demo_gridspec06_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np


    def squiggle_xy(a, b, c, d):
        i = np.arange(0.0, 2*np.pi, 0.05)
        return np.sin(i*a)*np.cos(i*b), np.sin(i*c)*np.cos(i*d)


    fig = plt.figure(figsize=(8, 8))
    outer_grid = fig.add_gridspec(4, 4, wspace=0, hspace=0)

    for a in range(4):
        for b in range(4):
            # gridspec inside gridspec
            inner_grid = outer_grid[a, b].subgridspec(3, 3, wspace=0, hspace=0)
            axs = inner_grid.subplots()  # Create all subplots for the inner grid.
            for (c, d), ax in np.ndenumerate(axs):
                ax.plot(*squiggle_xy(a + 1, b + 1, c + 1, d + 1))
                ax.set(xticks=[], yticks=[])

    # show only the outside spines
    for ax in fig.get_axes():
        ss = ax.get_subplotspec()
        ax.spines.top.set_visible(ss.is_first_row())
        ax.spines.bottom.set_visible(ss.is_last_row())
        ax.spines.left.set_visible(ss.is_first_col())
        ax.spines.right.set_visible(ss.is_last_col())

    plt.show()


.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_gallery_userdemo_demo_gridspec06.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

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

    .. container:: sphx-glr-download sphx-glr-download-python

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: demo_gridspec06.zip <demo_gridspec06.zip>`


.. only:: html

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

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
