.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/userdemo/connectionstyle_demo.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_userdemo_connectionstyle_demo.py: ================================= Connection styles for annotations ================================= When creating an annotation using `~.Axes.annotate`, the arrow shape can be controlled via the *connectionstyle* parameter of *arrowprops*. For further details see the description of `.FancyArrowPatch`. .. GENERATED FROM PYTHON SOURCE LINES 10-55 .. code-block:: Python import matplotlib.pyplot as plt def demo_con_style(ax, connectionstyle): x1, y1 = 0.3, 0.2 x2, y2 = 0.8, 0.6 ax.plot([x1, x2], [y1, y2], ".") ax.annotate("", xy=(x1, y1), xycoords='data', xytext=(x2, y2), textcoords='data', arrowprops=dict(arrowstyle="->", color="0.5", shrinkA=5, shrinkB=5, patchA=None, patchB=None, connectionstyle=connectionstyle, ), ) ax.text(.05, .95, connectionstyle.replace(",", ",\n"), transform=ax.transAxes, ha="left", va="top") fig, axs = plt.subplots(3, 5, figsize=(7, 6.3), layout="constrained") demo_con_style(axs[0, 0], "angle3,angleA=90,angleB=0") demo_con_style(axs[1, 0], "angle3,angleA=0,angleB=90") demo_con_style(axs[0, 1], "arc3,rad=0.") demo_con_style(axs[1, 1], "arc3,rad=0.3") demo_con_style(axs[2, 1], "arc3,rad=-0.3") demo_con_style(axs[0, 2], "angle,angleA=-90,angleB=180,rad=0") demo_con_style(axs[1, 2], "angle,angleA=-90,angleB=180,rad=5") demo_con_style(axs[2, 2], "angle,angleA=-90,angleB=10,rad=5") demo_con_style(axs[0, 3], "arc,angleA=-90,angleB=0,armA=30,armB=30,rad=0") demo_con_style(axs[1, 3], "arc,angleA=-90,angleB=0,armA=30,armB=30,rad=5") demo_con_style(axs[2, 3], "arc,angleA=-90,angleB=0,armA=0,armB=40,rad=0") demo_con_style(axs[0, 4], "bar,fraction=0.3") demo_con_style(axs[1, 4], "bar,fraction=-0.3") demo_con_style(axs[2, 4], "bar,angle=180,fraction=-0.2") for ax in axs.flat: ax.set(xlim=(0, 1), ylim=(0, 1.25), xticks=[], yticks=[], aspect=1.25) fig.get_layout_engine().set(wspace=0, hspace=0, w_pad=0, h_pad=0) plt.show() .. image-sg:: /gallery/userdemo/images/sphx_glr_connectionstyle_demo_001.png :alt: connectionstyle demo :srcset: /gallery/userdemo/images/sphx_glr_connectionstyle_demo_001.png, /gallery/userdemo/images/sphx_glr_connectionstyle_demo_001_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-63 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.axes.Axes.annotate` - `matplotlib.patches.FancyArrowPatch` .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.086 seconds) .. _sphx_glr_download_gallery_userdemo_connectionstyle_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: connectionstyle_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: connectionstyle_demo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_