.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/images_contours_and_fields/image_clip_path.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_images_contours_and_fields_image_clip_path.py: ============================ Clipping images with patches ============================ Demo of image that's been clipped by a circular patch. .. GENERATED FROM PYTHON SOURCE LINES 8-24 .. code-block:: Python import matplotlib.pyplot as plt import matplotlib.cbook as cbook import matplotlib.patches as patches with cbook.get_sample_data('grace_hopper.jpg') as image_file: image = plt.imread(image_file) fig, ax = plt.subplots() im = ax.imshow(image) patch = patches.Circle((260, 200), radius=200, transform=ax.transData) im.set_clip_path(patch) ax.axis('off') plt.show() .. image-sg:: /gallery/images_contours_and_fields/images/sphx_glr_image_clip_path_001.png :alt: image clip path :srcset: /gallery/images_contours_and_fields/images/sphx_glr_image_clip_path_001.png, /gallery/images_contours_and_fields/images/sphx_glr_image_clip_path_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 25-32 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.axes.Axes.imshow` / `matplotlib.pyplot.imshow` - `matplotlib.artist.Artist.set_clip_path` .. _sphx_glr_download_gallery_images_contours_and_fields_image_clip_path.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: image_clip_path.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: image_clip_path.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_