Skip to content

Commit 41ccf2b

Browse files
author
Tim Hoffmann
committed
Replace transAxes example in Annotations tutorial
Drawing a connection between two related data points seems a more real-world application than annotating one text with another text from another Axes.
1 parent 75a20ff commit 41ccf2b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

galleries/users_explain/text/annotations.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,17 +575,19 @@ def custom_box_style(x0, y0, width, height, mutation_size):
575575
# %%
576576
# Another commonly used `.Transform` instance is ``Axes.transData``. This
577577
# transform is the coordinate system of the data plotted in the axes. In this
578-
# example, it is used to draw an arrow from a point in *ax1* to text in *ax2*,
579-
# where the point and text are positioned relative to the coordinates of *ax1*
580-
# and *ax2* respectively:
578+
# example, it is used to draw an arrow between related data points in two
579+
# Axes. We have passed an empty text because in this case, the annotation
580+
# connects data points.
581581

582-
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(6, 3))
582+
x = np.linspace(-1, 1)
583583

584-
ax1.annotate("Test1", xy=(0.5, 0.5), xycoords="axes fraction")
585-
ax2.annotate("Test2",
586-
xy=(0.5, 0.5), xycoords=ax1.transData,
587-
xytext=(0.5, 0.5), textcoords=ax2.transData,
588-
arrowprops=dict(arrowstyle="->"))
584+
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(6, 3))
585+
ax1.plot(x, -x**3)
586+
ax2.plot(x, -3*x**2)
587+
ax2.annotate("",
588+
xy=(0, 0), xycoords=ax1.transData,
589+
xytext=(0, 0), textcoords=ax2.transData,
590+
arrowprops=dict(arrowstyle="<->"))
589591

590592
# %%
591593
# .. _artist_annotation_coord:

0 commit comments

Comments
 (0)