{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Clipping images with patches\n\nDemo of image that's been clipped by a circular patch.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from PIL import Image\n\nimport matplotlib.pyplot as plt\n\nimport matplotlib.cbook as cbook\nimport matplotlib.patches as patches\n\nimage = Image.open(cbook.get_sample_data(\"grace_hopper.jpg\"))\n\nfig, ax = plt.subplots()\nim = ax.imshow(image)\npatch = patches.Circle((260, 200), radius=200, transform=ax.transData)\nim.set_clip_path(patch)\n\nax.axis('off')\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `matplotlib.axes.Axes.imshow` / `matplotlib.pyplot.imshow`\n - `matplotlib.artist.Artist.set_clip_path`\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.15" } }, "nbformat": 4, "nbformat_minor": 0 }