.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plot_02_simple_inset_view.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. 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_examples_plot_02_simple_inset_view.py: Create An Inset Axes Without Plotting Twice =========================================== :meth:`matplotview.inset_zoom_axes` can be utilized to create inset axes where we don't have to plot the parent axes data twice. .. GENERATED FROM PYTHON SOURCE LINES 8-43 .. image-sg:: /examples/images/sphx_glr_plot_02_simple_inset_view_001.png :alt: plot 02 simple inset view :srcset: /examples/images/sphx_glr_plot_02_simple_inset_view_001.png :class: sphx-glr-single-img .. code-block:: default :lineno-start: 9 from matplotlib import cbook import matplotlib.pyplot as plt import numpy as np from matplotview import inset_zoom_axes 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() # Make the 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, interpolation='nearest', origin="lower") # Creates an inset axes with automatic view of the parent axes... axins = inset_zoom_axes(ax, [0.5, 0.5, 0.47, 0.47]) # Set limits to 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) # Remove the tick labels from the inset axes axins.set_xticklabels([]) axins.set_yticklabels([]) # Draw the indicator or zoom lines. ax.indicate_inset_zoom(axins, edgecolor="black") fig.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.190 seconds) .. _sphx_glr_download_examples_plot_02_simple_inset_view.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_simple_inset_view.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_simple_inset_view.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_