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

Skip to content

Commit 78442c4

Browse files
authored
Merge pull request #25100 from story645/annotate-artist
add section on annotating an artist using axes.annotate
2 parents 38abc71 + bd94bd9 commit 78442c4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tutorials/text/annotations.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@
9292

9393
# %%
9494
#
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+
#
95119
# .. _annotation-with-arrow:
96120
#
97121
# Annotating with arrows
@@ -551,6 +575,8 @@ def custom_box_style(x0, y0, width, height, mutation_size):
551575
arrowprops=dict(arrowstyle="->"))
552576

553577
# %%
578+
# .. _artist_annotation_coord:
579+
#
554580
# 2. An `.Artist` instance. The *xy* value (or *xytext*) is interpreted as a
555581
# fractional coordinate of the bounding box (bbox) of the artist:
556582

0 commit comments

Comments
 (0)