|
23 | 23 | 3. Entire patch fixed in data space
|
24 | 24 |
|
25 | 25 | Below each use case is presented in turn.
|
| 26 | +
|
| 27 | +.. redirect-from:: /gallery/text_labels_and_annotations/arrow_simple_demo |
26 | 28 | """
|
| 29 | + |
27 | 30 | import matplotlib.patches as mpatches
|
28 | 31 | import matplotlib.pyplot as plt
|
29 | 32 | x_tail = 0.1
|
30 |
| -y_tail = 0.1 |
| 33 | +y_tail = 0.5 |
31 | 34 | x_head = 0.9
|
32 |
| -y_head = 0.9 |
| 35 | +y_head = 0.8 |
33 | 36 | dx = x_head - x_tail
|
34 | 37 | dy = y_head - y_tail
|
35 | 38 |
|
|
54 | 57 | arrow = mpatches.FancyArrowPatch((x_tail, y_tail), (x_head, y_head),
|
55 | 58 | mutation_scale=100)
|
56 | 59 | 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)) |
59 | 61 |
|
60 | 62 | ###############################################################################
|
61 | 63 | # Head shape and anchor points fixed in display space
|
|
81 | 83 | mutation_scale=100,
|
82 | 84 | transform=axs[1].transAxes)
|
83 | 85 | 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)) |
86 | 87 |
|
87 | 88 |
|
88 | 89 | ###############################################################################
|
89 | 90 | # Head shape and anchor points fixed in data space
|
90 | 91 | # ------------------------------------------------
|
91 | 92 | #
|
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). |
93 | 95 | #
|
94 | 96 | # Note that when the axis limits are changed, the arrow shape and location
|
95 | 97 | # 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). |
96 | 103 |
|
97 | 104 | fig, axs = plt.subplots(nrows=2)
|
98 | 105 |
|
99 | 106 | arrow = mpatches.Arrow(x_tail, y_tail, dx, dy)
|
100 | 107 | 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") |
101 | 113 |
|
102 | 114 | arrow = mpatches.Arrow(x_tail, y_tail, dx, dy)
|
103 | 115 | 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)) |
106 | 122 |
|
107 | 123 | ###############################################################################
|
108 | 124 |
|
|
0 commit comments