Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4ac442

Browse filesBrowse files
authored
Merge pull request #20386 from anntzer/ad
Merge arrow_simple_demo into arrow_guide.
2 parents d0ad9b0 + 91c60b7 commit d4ac442
Copy full SHA for d4ac442

File tree

Expand file treeCollapse file tree

2 files changed

+25
-20
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-20
lines changed

‎examples/shapes_and_collections/arrow_guide.py

Copy file name to clipboardExpand all lines: examples/shapes_and_collections/arrow_guide.py
+25-9Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
3. Entire patch fixed in data space
2424
2525
Below each use case is presented in turn.
26+
27+
.. redirect-from:: /gallery/text_labels_and_annotations/arrow_simple_demo
2628
"""
29+
2730
import matplotlib.patches as mpatches
2831
import matplotlib.pyplot as plt
2932
x_tail = 0.1
30-
y_tail = 0.1
33+
y_tail = 0.5
3134
x_head = 0.9
32-
y_head = 0.9
35+
y_head = 0.8
3336
dx = x_head - x_tail
3437
dy = y_head - y_tail
3538

@@ -54,8 +57,7 @@
5457
arrow = mpatches.FancyArrowPatch((x_tail, y_tail), (x_head, y_head),
5558
mutation_scale=100)
5659
axs[1].add_patch(arrow)
57-
axs[1].set_xlim(0, 2)
58-
axs[1].set_ylim(0, 2)
60+
axs[1].set(xlim=(0, 2), ylim=(0, 2))
5961

6062
###############################################################################
6163
# Head shape and anchor points fixed in display space
@@ -81,28 +83,42 @@
8183
mutation_scale=100,
8284
transform=axs[1].transAxes)
8385
axs[1].add_patch(arrow)
84-
axs[1].set_xlim(0, 2)
85-
axs[1].set_ylim(0, 2)
86+
axs[1].set(xlim=(0, 2), ylim=(0, 2))
8687

8788

8889
###############################################################################
8990
# Head shape and anchor points fixed in data space
9091
# ------------------------------------------------
9192
#
92-
# In this case we use `.patches.Arrow`.
93+
# In this case we use `.patches.Arrow`, or `.patches.FancyArrow` (the latter is
94+
# in orange).
9395
#
9496
# Note that when the axis limits are changed, the arrow shape and location
9597
# change.
98+
#
99+
# `.FancyArrow`'s API is relatively awkward, and requires in particular passing
100+
# ``length_includes_head=True`` so that the arrow *tip* is ``(dx, dy)`` away
101+
# from the arrow start. It is only included in this reference because it is
102+
# the arrow class returned by `.Axes.arrow` (in green).
96103

97104
fig, axs = plt.subplots(nrows=2)
98105

99106
arrow = mpatches.Arrow(x_tail, y_tail, dx, dy)
100107
axs[0].add_patch(arrow)
108+
arrow = mpatches.FancyArrow(x_tail, y_tail - .4, dx, dy,
109+
width=.1, length_includes_head=True, color="C1")
110+
axs[0].add_patch(arrow)
111+
axs[0].arrow(x_tail + 1, y_tail - .4, dx, dy,
112+
width=.1, length_includes_head=True, color="C2")
101113

102114
arrow = mpatches.Arrow(x_tail, y_tail, dx, dy)
103115
axs[1].add_patch(arrow)
104-
axs[1].set_xlim(0, 2)
105-
axs[1].set_ylim(0, 2)
116+
arrow = mpatches.FancyArrow(x_tail, y_tail - .4, dx, dy,
117+
width=.1, length_includes_head=True, color="C1")
118+
axs[1].add_patch(arrow)
119+
axs[1].arrow(x_tail + 1, y_tail - .4, dx, dy,
120+
width=.1, length_includes_head=True, color="C2")
121+
axs[1].set(xlim=(0, 2), ylim=(0, 2))
106122

107123
###############################################################################
108124

‎examples/text_labels_and_annotations/arrow_simple_demo.py

Copy file name to clipboardExpand all lines: examples/text_labels_and_annotations/arrow_simple_demo.py
-11Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.