
.. 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

    .. meta::
        :keywords: codex

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

        :ref:`Go to the end <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-36

.. code-block:: Python


    import numpy as np

    from matplotlib import cbook
    from matplotlib import pyplot as plt

    fig, ax = plt.subplots()

    # make data
    Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy")  # 15x15 array
    Z2 = np.zeros((150, 150))
    ny, nx = Z.shape
    Z2[30:30+ny, 30:30+nx] = Z
    extent = (-3, 4, -4, 3)

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

    # inset Axes....
    x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9  # subregion of the original image
    axins = ax.inset_axes(
        [0.5, 0.5, 0.47, 0.47],
        xlim=(x1, x2), ylim=(y1, y2), xticklabels=[], yticklabels=[])
    axins.imshow(Z2, extent=extent, origin="lower")

    ax.indicate_inset_zoom(axins, edgecolor="black")

    plt.show()


.. GENERATED FROM PYTHON SOURCE LINES 37-51

.. admonition:: References

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

   - `matplotlib.axes.Axes.inset_axes`
   - `matplotlib.axes.Axes.indicate_inset_zoom`
   - `matplotlib.axes.Axes.imshow`

.. tags::

   component: axes
   plot-type: imshow
   level: intermediate


.. _sphx_glr_download_gallery_subplots_axes_and_figures_zoom_inset_axes.py:

.. only:: html

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

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

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

    .. 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-zip

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


.. only:: html

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

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