.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plot_11_image_interpolation.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_11_image_interpolation.py: Image Interpolation Methods =========================== :meth:`matplotview.view` and :meth:`matplotview.inset_zoom_axes` support specifying an image interpolation method via the `image_interpolation` parameter. This image interpolation method is used to resize images when displaying them in the view. .. GENERATED FROM PYTHON SOURCE LINES 9-31 .. code-block:: default :lineno-start: 9 import matplotlib.pyplot as plt from matplotview import view import numpy as np fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) fig.suptitle("Different interpolations when zoomed in on the bottom left corner.") ax1.set_title("Original") ax1.imshow(np.random.rand(100, 100), cmap="Blues", origin="lower") ax1.add_patch(plt.Rectangle((0, 0), 10, 10, ec="red", fc=(0, 0, 0, 0))) for ax, interpolation, title in zip([ax2, ax3, ax4], ["nearest", "bilinear", "bicubic"], ["Nearest (Default)", "Bilinear", "Cubic"]): ax.set_title(title) ax.set_xlim(0, 10) ax.set_ylim(0, 10) ax.set_aspect("equal") view(ax, ax1, image_interpolation=interpolation) fig.tight_layout() fig.show() .. image-sg:: /examples/images/sphx_glr_plot_11_image_interpolation_001.png :alt: Different interpolations when zoomed in on the bottom left corner., Original, Nearest (Default), Bilinear, Cubic :srcset: /examples/images/sphx_glr_plot_11_image_interpolation_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 32-33 If you want to avoid interpolation artifacts, you can use `pcolormesh` instead of `imshow`. .. GENERATED FROM PYTHON SOURCE LINES 33-52 .. code-block:: default :lineno-start: 34 import matplotlib.pyplot as plt from matplotview import view import numpy as np fig, (ax1, ax2) = plt.subplots(1, 2) ax1.set_title("Original") ax1.pcolormesh(np.random.rand(100, 100), cmap="Blues") ax1.add_patch(plt.Rectangle((0, 0), 10, 10, ec="red", fc=(0, 0, 0, 0))) ax1.set_aspect("equal") ax2.set_title("Zoomed in View") ax2.set_xlim(0, 10) ax2.set_ylim(0, 10) ax2.set_aspect("equal") view(ax2, ax1) fig.tight_layout() fig.show() .. image-sg:: /examples/images/sphx_glr_plot_11_image_interpolation_002.png :alt: Original, Zoomed in View :srcset: /examples/images/sphx_glr_plot_11_image_interpolation_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.037 seconds) .. _sphx_glr_download_examples_plot_11_image_interpolation.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_11_image_interpolation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_11_image_interpolation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_