{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Annotation arrow style reference\n\nOverview of the arrow styles available in `~.Axes.annotate`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import inspect\nimport itertools\nimport re\n\nimport matplotlib.pyplot as plt\n\nimport matplotlib.patches as mpatches\n\nstyles = mpatches.ArrowStyle.get_styles()\nncol = 2\nnrow = (len(styles) + 1) // ncol\naxs = (plt.figure(figsize=(4 * ncol, 1 + nrow))\n .add_gridspec(1 + nrow, ncol,\n wspace=.7, left=.1, right=.9, bottom=0, top=1).subplots())\nfor ax in axs.flat:\n ax.set_axis_off()\nfor ax in axs[0, :]:\n ax.text(0, .5, \"arrowstyle\",\n transform=ax.transAxes, size=\"large\", color=\"tab:blue\",\n horizontalalignment=\"center\", verticalalignment=\"center\")\n ax.text(.35, .5, \"default parameters\",\n transform=ax.transAxes,\n horizontalalignment=\"left\", verticalalignment=\"center\")\nfor ax, (stylename, stylecls) in zip(axs[1:, :].T.flat, styles.items()):\n l, = ax.plot(.25, .5, \"ok\", transform=ax.transAxes)\n ax.annotate(stylename, (.25, .5), (-0.1, .5),\n xycoords=\"axes fraction\", textcoords=\"axes fraction\",\n size=\"large\", color=\"tab:blue\",\n horizontalalignment=\"center\", verticalalignment=\"center\",\n arrowprops=dict(\n arrowstyle=stylename, connectionstyle=\"arc3,rad=-0.05\",\n color=\"k\", shrinkA=5, shrinkB=5, patchB=l,\n ),\n bbox=dict(boxstyle=\"square\", fc=\"w\"))\n # wrap at every nth comma (n = 1 or 2, depending on text length)\n s = str(inspect.signature(stylecls))[1:-1]\n n = 2 if s.count(',') > 3 else 1\n ax.text(.35, .5,\n re.sub(', ', lambda m, c=itertools.count(1): m.group()\n if next(c) % n else '\\n', s),\n transform=ax.transAxes,\n horizontalalignment=\"left\", verticalalignment=\"center\")\n\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.patches`\n - `matplotlib.patches.ArrowStyle`\n - ``matplotlib.patches.ArrowStyle.get_styles``\n - `matplotlib.axes.Axes.annotate`\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 }