|
92 | 92 |
|
93 | 93 | # %%
|
94 | 94 | #
|
| 95 | +# Annotating an Artist |
| 96 | +# ~~~~~~~~~~~~~~~~~~~~ |
| 97 | +# |
| 98 | +# Annotations can be positioned relative to an `.Artist` instance by passing |
| 99 | +# that Artist in as *xycoords*. Then *xy* is interpreted as a fraction of the |
| 100 | +# Artist's bounding box. |
| 101 | + |
| 102 | +import matplotlib.patches as mpatches |
| 103 | + |
| 104 | +fig, ax = plt.subplots(figsize=(3, 3)) |
| 105 | +arr = mpatches.FancyArrowPatch((1.25, 1.25), (1.75, 1.75), |
| 106 | + arrowstyle='->,head_width=.15', mutation_scale=20) |
| 107 | +ax.add_patch(arr) |
| 108 | +ax.annotate("label", (.5, .5), xycoords=arr, ha='center', va='center') |
| 109 | +ax.set(xlim=(1, 2), ylim=(1, 2)) |
| 110 | + |
| 111 | +# %% |
| 112 | +# Here the annotation is placed at position (.5,.5) relative to the arrow's |
| 113 | +# lower left corner and is vertically and horizontally centered at that |
| 114 | +# position. For an example of chaining annotation Artists, see the |
| 115 | +# :ref:`Artist section <artist_annotation_coord>` of |
| 116 | +# :ref:`annotating_coordinate_systems`. |
| 117 | +# |
| 118 | +# |
95 | 119 | # .. _annotation-with-arrow:
|
96 | 120 | #
|
97 | 121 | # Annotating with arrows
|
@@ -551,6 +575,8 @@ def custom_box_style(x0, y0, width, height, mutation_size):
|
551 | 575 | arrowprops=dict(arrowstyle="->"))
|
552 | 576 |
|
553 | 577 | # %%
|
| 578 | +# .. _artist_annotation_coord: |
| 579 | +# |
554 | 580 | # 2. An `.Artist` instance. The *xy* value (or *xytext*) is interpreted as a
|
555 | 581 | # fractional coordinate of the bounding box (bbox) of the artist:
|
556 | 582 |
|
|
0 commit comments