From 0eed653805124aff8270683a024b6b3dca52c713 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 10 Apr 2019 06:45:11 +0200 Subject: [PATCH] Backport PR #13835: Improve Conectionstyle Demo --- .flake8 | 1 + examples/userdemo/connectionstyle_demo.py | 33 +++++++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.flake8 b/.flake8 index 546c5f39d628..aa7c8e5dd2ed 100644 --- a/.flake8 +++ b/.flake8 @@ -257,6 +257,7 @@ per-file-ignores = examples/user_interfaces/mpl_with_glade3_sgskip.py: E402 examples/user_interfaces/pylab_with_gtk_sgskip.py: E302, E402 examples/user_interfaces/toolmanager_sgskip.py: E402 + examples/userdemo/connectionstyle_demo.py: E402 examples/userdemo/custom_boxstyle01.py: E402 examples/userdemo/pgf_preamble_sgskip.py: E402 examples/userdemo/simple_annotate01.py: E501 diff --git a/examples/userdemo/connectionstyle_demo.py b/examples/userdemo/connectionstyle_demo.py index 1ea2bf5fe8fd..d429822b6965 100644 --- a/examples/userdemo/connectionstyle_demo.py +++ b/examples/userdemo/connectionstyle_demo.py @@ -3,17 +3,15 @@ Connectionstyle Demo ==================== +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`. """ import matplotlib.pyplot as plt -fig, axs = plt.subplots(3, 5, figsize=(8, 4.8)) -x1, y1 = 0.3, 0.3 -x2, y2 = 0.7, 0.7 - - -def demo_con_style(ax, connectionstyle, label=None): +def demo_con_style(ax, connectionstyle): x1, y1 = 0.3, 0.2 x2, y2 = 0.8, 0.6 @@ -21,11 +19,9 @@ def demo_con_style(ax, connectionstyle, label=None): ax.annotate("", xy=(x1, y1), xycoords='data', xytext=(x2, y2), textcoords='data', - arrowprops=dict(arrowstyle="->", - color="0.5", + arrowprops=dict(arrowstyle="->", color="0.5", shrinkA=5, shrinkB=5, - patchA=None, - patchB=None, + patchA=None, patchB=None, connectionstyle=connectionstyle, ), ) @@ -34,6 +30,7 @@ def demo_con_style(ax, connectionstyle, label=None): transform=ax.transAxes, ha="left", va="top") +fig, axs = plt.subplots(3, 5, figsize=(8, 4.8)) 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.") @@ -51,6 +48,20 @@ def demo_con_style(ax, connectionstyle, label=None): for ax in axs.flat: ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1) -fig.tight_layout(pad=0) +fig.tight_layout(pad=0.2) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.annotate +matplotlib.patches.FancyArrowPatch