Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #13835 on branch v3.1.x (Improve Conectionstyle Demo) #13915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 22 additions & 11 deletions examples/userdemo/connectionstyle_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
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

ax.plot([x1, x2], [y1, y2], ".")
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,
),
)
Expand All @@ -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.")
Expand All @@ -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