.. 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 ` 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() .. image-sg:: /gallery/subplots_axes_and_figures/images/sphx_glr_zoom_inset_axes_001.png :alt: zoom inset axes :srcset: /gallery/subplots_axes_and_figures/images/sphx_glr_zoom_inset_axes_001.png, /gallery/subplots_axes_and_figures/images/sphx_glr_zoom_inset_axes_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. 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` .. _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 ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: zoom_inset_axes.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_