{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Reference for Matplotlib artists\n\nThis example displays several of Matplotlib's graphics primitives (artists).\nA full list of artists is documented at `the artist API `.\n\nSee also :doc:`/gallery/shapes_and_collections/patch_collection`, which groups\nall artists into a single `.PatchCollection` instead.\n\nCopyright (c) 2010, Bartosz Telenczuk\nBSD License\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nimport matplotlib as mpl\nimport matplotlib.lines as mlines\nimport matplotlib.patches as mpatches\nimport matplotlib.path as mpath\n\n# Prepare the data for the PathPatch below.\nPath = mpath.Path\ncodes, verts = zip(*[\n (Path.MOVETO, [0.018, -0.11]),\n (Path.CURVE4, [-0.031, -0.051]),\n (Path.CURVE4, [-0.115, 0.073]),\n (Path.CURVE4, [-0.03, 0.073]),\n (Path.LINETO, [-0.011, 0.039]),\n (Path.CURVE4, [0.043, 0.121]),\n (Path.CURVE4, [0.075, -0.005]),\n (Path.CURVE4, [0.035, -0.027]),\n (Path.CLOSEPOLY, [0.018, -0.11])])\n\nartists = [\n mpatches.Circle((0, 0), 0.1, ec=\"none\"),\n mpatches.Rectangle((-0.025, -0.05), 0.05, 0.1, ec=\"none\"),\n mpatches.Wedge((0, 0), 0.1, 30, 270, ec=\"none\"),\n mpatches.RegularPolygon((0, 0), 5, radius=0.1),\n mpatches.Ellipse((0, 0), 0.2, 0.1),\n mpatches.Arrow(-0.05, -0.05, 0.1, 0.1, width=0.1),\n mpatches.PathPatch(mpath.Path(verts, codes), ec=\"none\"),\n mpatches.FancyBboxPatch((-0.025, -0.05), 0.05, 0.1, ec=\"none\",\n boxstyle=mpatches.BoxStyle(\"Round\", pad=0.02)),\n mlines.Line2D([-0.06, 0.0, 0.1], [0.05, -0.05, 0.05], lw=5),\n]\n\naxs = plt.figure(figsize=(6, 6), layout=\"constrained\").subplots(3, 3)\nfor i, (ax, artist) in enumerate(zip(axs.flat, artists)):\n artist.set(color=mpl.colormaps[\"hsv\"](i / len(artists)))\n ax.add_artist(artist)\n ax.set(title=type(artist).__name__,\n aspect=1, xlim=(-.2, .2), ylim=(-.2, .2))\n ax.set_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.path`\n - `matplotlib.path.Path`\n - `matplotlib.lines`\n - `matplotlib.lines.Line2D`\n - `matplotlib.patches`\n - `matplotlib.patches.Circle`\n - `matplotlib.patches.Ellipse`\n - `matplotlib.patches.Wedge`\n - `matplotlib.patches.Rectangle`\n - `matplotlib.patches.Arrow`\n - `matplotlib.patches.PathPatch`\n - `matplotlib.patches.FancyBboxPatch`\n - `matplotlib.patches.RegularPolygon`\n - `matplotlib.axes.Axes.add_artist`\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.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }