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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_subplots_axes_and_figures_zoom_inset_axes.py>`
        to download the full example code

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

.. _sphx_glr_gallery_subplots_axes_and_figures_zoom_inset_axes.py:


======================
Zoom region inset axes
======================

Example of an inset axes and a rectangle showing where the zoom is located.

.. GENERATED FROM PYTHON SOURCE LINES 8-43

.. code-block:: default


    from matplotlib import cbook
    import matplotlib.pyplot as plt
    import numpy as np


    def get_demo_image():
        z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
        # z is a numpy array of 15x15
        return z, (-3, 4, -4, 3)

    fig, ax = plt.subplots(figsize=[5, 4])

    # make data
    Z, extent = get_demo_image()
    Z2 = np.zeros((150, 150))
    ny, nx = Z.shape
    Z2[30:30+ny, 30:30+nx] = Z

    ax.imshow(Z2, extent=extent, origin="lower")

    # inset axes....
    axins = ax.inset_axes([0.5, 0.5, 0.47, 0.47])
    axins.imshow(Z2, extent=extent, origin="lower")
    # sub region of the original image
    x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
    axins.set_xlim(x1, x2)
    axins.set_ylim(y1, y2)
    axins.set_xticklabels('')
    axins.set_yticklabels('')

    ax.indicate_inset_zoom(axins)

    plt.show()




.. image:: /gallery/subplots_axes_and_figures/images/sphx_glr_zoom_inset_axes_001.png
    :alt: zoom inset axes
    :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 44-50

------------

References
""""""""""

The use of the following functions and methods is shown in this example:

.. GENERATED FROM PYTHON SOURCE LINES 51-56

.. code-block:: default


    import matplotlib
    matplotlib.axes.Axes.inset_axes
    matplotlib.axes.Axes.indicate_inset_zoom
    matplotlib.axes.Axes.imshow




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none


    <function Axes.imshow at 0x7f73be8fc820>




.. _sphx_glr_download_gallery_subplots_axes_and_figures_zoom_inset_axes.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: zoom_inset_axes.py <zoom_inset_axes.py>`



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

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
