5
5
.. redirect-from:: /gallery/userdemo/annotate_simple04
6
6
.. redirect-from:: /gallery/userdemo/anchored_box04
7
7
.. redirect-from:: /gallery/userdemo/annotate_simple_coord01
8
+ .. redirect-from:: /gallery/userdemo/annotate_simple_coord02
8
9
.. redirect-from:: /gallery/userdemo/annotate_simple_coord03
10
+ .. redirect-from:: /gallery/userdemo/connect_simple01
9
11
.. redirect-from:: /tutorials/text/annotations
10
12
11
13
.. _annotations:
85
87
# .. _annotation-data:
86
88
#
87
89
# Annotating data
88
- # ~~~~~~~~~~~~~~~
90
+ # ^^^^^^^^^^^^^^^
89
91
#
90
92
# This example places the text coordinates in fractional axes coordinates:
91
93
104
106
# %%
105
107
#
106
108
# Annotating an Artist
107
- # ~~~~~~~~~~~~~~~~~~~~
109
+ # ^^^^^^^^^^^^^^^^^^^^
108
110
#
109
111
# Annotations can be positioned relative to an `.Artist` instance by passing
110
112
# that Artist in as *xycoords*. Then *xy* is interpreted as a fraction of the
131
133
# .. _annotation-with-arrow:
132
134
#
133
135
# Annotating with arrows
134
- # ~~~~~~~~~~~~~~~~~~~~~~
136
+ # ^^^^^^^^^^^^^^^^^^^^^^
135
137
#
136
138
# You can enable drawing of an arrow from the text to the annotated point
137
139
# by giving a dictionary of arrow properties in the optional keyword
181
183
# .. _annotations-offset-text:
182
184
#
183
185
# Placing text annotations relative to data
184
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185
187
#
186
188
# Annotations can be positioned at a relative offset to the *xy* input to
187
189
# annotation by setting the *textcoords* keyword argument to ``'offset points'``
210
212
# and :func:`~matplotlib.pyplot.annotate` before reading this section.
211
213
#
212
214
# Annotating with boxed text
213
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~
215
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^
214
216
#
215
217
# `~.Axes.text` takes a *bbox* keyword argument, which draws a box around the
216
218
# text:
261
263
#
262
264
#
263
265
# Defining custom box styles
264
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~
266
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^
265
267
#
266
268
# You can use a custom box style. The value for the ``boxstyle`` can be a
267
269
# callable object in the following forms:
@@ -307,7 +309,7 @@ def custom_box_style(x0, y0, width, height, mutation_size):
307
309
# .. _annotation_with_custom_arrow:
308
310
#
309
311
# Customizing annotation arrows
310
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
311
313
#
312
314
# An arrow connecting *xy* to *xytext* can be optionally drawn by
313
315
# specifying the *arrowprops* argument. To draw only an arrow, use
@@ -446,7 +448,7 @@ def custom_box_style(x0, y0, width, height, mutation_size):
446
448
447
449
# %%
448
450
# Placing Artist at anchored Axes locations
449
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
450
452
#
451
453
# There are classes of artists that can be placed at an anchored
452
454
# location in the Axes. A common example is the legend. This type
@@ -562,11 +564,15 @@ def custom_box_style(x0, y0, width, height, mutation_size):
562
564
# examples in :ref:`annotations-tutorial` used the ``data`` coordinate system;
563
565
# Some others more advanced options are:
564
566
#
565
- # 1. A `.Transform` instance. For more information on transforms, see the
566
- # :ref:`transforms_tutorial` For example, the
567
- # ``Axes.transAxes`` transform positions the annotation relative to the Axes
568
- # coordinates and using it is therefore identical to setting the
569
- # coordinate system to "axes fraction":
567
+ # `.Transform` instance
568
+ # ^^^^^^^^^^^^^^^^^^^^^
569
+ #
570
+ # Transforms map coordinates into different coordinate systems, usually the
571
+ # display coordinate system. See :ref:`transforms_tutorial` for a detailed
572
+ # explanation. Here Transform objects are used to identify the coordinate
573
+ # system of the corresponding points. For example, the ``Axes.transAxes``
574
+ # transform positions the annotation relative to the Axes coordinates; therefore
575
+ # using it is identical to setting the coordinate system to "axes fraction":
570
576
571
577
fig , (ax1 , ax2 ) = plt .subplots (nrows = 1 , ncols = 2 , figsize = (6 , 3 ))
572
578
ax1 .annotate ("Test" , xy = (0.2 , 0.2 ), xycoords = ax1 .transAxes )
@@ -592,8 +598,11 @@ def custom_box_style(x0, y0, width, height, mutation_size):
592
598
# %%
593
599
# .. _artist_annotation_coord:
594
600
#
595
- # 2. An `.Artist` instance. The *xy* value (or *xytext*) is interpreted as a
596
- # fractional coordinate of the bounding box (bbox) of the artist:
601
+ # `.Artist` instance
602
+ # ^^^^^^^^^^^^^^^^^^
603
+ #
604
+ # The *xy* value (or *xytext*) is interpreted as a fractional coordinate of the
605
+ # bounding box (bbox) of the artist:
597
606
598
607
fig , ax = plt .subplots (nrows = 1 , ncols = 1 , figsize = (3 , 3 ))
599
608
an1 = ax .annotate ("Test 1" ,
@@ -614,7 +623,10 @@ def custom_box_style(x0, y0, width, height, mutation_size):
614
623
# that *an2* needs to be drawn after *an1*. The base class for all bounding
615
624
# boxes is `.BboxBase`
616
625
#
617
- # 3. A callable object that takes the renderer instance as single argument, and
626
+ # Callable that returns `.Transform` of `.BboxBase`
627
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
628
+ #
629
+ # A callable object that takes the renderer instance as single argument, and
618
630
# returns either a `.Transform` or a `.BboxBase`. For example, the return
619
631
# value of `.Artist.get_window_extent` is a bbox, so this method is identical
620
632
# to (2) passing in the artist:
@@ -642,7 +654,10 @@ def custom_box_style(x0, y0, width, height, mutation_size):
642
654
an2 = ax2 .annotate ("Test 2" , xy = (0.5 , 0.5 ), xycoords = ax2 .get_window_extent )
643
655
644
656
# %%
645
- # 4. A blended pair of coordinate specifications -- the first for the
657
+ # Blended coordinate specification
658
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
659
+ #
660
+ # A blended pair of coordinate specifications -- the first for the
646
661
# x-coordinate, and the second is for the y-coordinate. For example, x=0.5 is
647
662
# in data coordinates, and y=1 is in normalized axes coordinates:
648
663
@@ -652,7 +667,22 @@ def custom_box_style(x0, y0, width, height, mutation_size):
652
667
ax .set (xlim = (0 , 2 ), ylim = (1 , 2 ))
653
668
654
669
# %%
655
- # 5. Sometimes, you want your annotation with some "offset points", not from the
670
+ # Any of the supported coordinate systems can be used in a blended
671
+ # specification. For example, the text "Anchored to 1 & 2" is positioned
672
+ # relative to the two `.Text` Artists:
673
+
674
+ fig , ax = plt .subplots (figsize = (3 , 3 ))
675
+
676
+ t1 = ax .text (0.05 , .05 , "Text 1" , va = 'bottom' , ha = 'left' )
677
+ t2 = ax .text (0.90 , .90 , "Text 2" , ha = 'right' )
678
+ t3 = ax .annotate ("Anchored to 1 & 2" , xy = (0 , 0 ), xycoords = (t1 , t2 ),
679
+ va = 'bottom' , color = 'tab:orange' ,)
680
+
681
+ # %%
682
+ # `.text.OffsetFrom`
683
+ # ^^^^^^^^^^^^^^^^^^
684
+ #
685
+ # Sometimes, you want your annotation with some "offset points", not from the
656
686
# annotated point but from some other point or artist. `.text.OffsetFrom` is
657
687
# a helper for such cases.
658
688
@@ -672,8 +702,13 @@ def custom_box_style(x0, y0, width, height, mutation_size):
672
702
arrowprops = dict (arrowstyle = "->" ))
673
703
674
704
# %%
705
+ # Non-text annotations
706
+ # --------------------
707
+ #
708
+ # .. _using_connectionpatch:
709
+ #
675
710
# Using ConnectionPatch
676
- # ~~~~~~~~~~~~~~~~~~~~~
711
+ # ^^^^^^^^^^^^^^^^^^^^^
677
712
#
678
713
# `.ConnectionPatch` is like an annotation without text. While `~.Axes.annotate`
679
714
# is sufficient in most situations, `.ConnectionPatch` is useful when you want
@@ -698,7 +733,7 @@ def custom_box_style(x0, y0, width, height, mutation_size):
698
733
# for positioning the axes.
699
734
#
700
735
# Zoom effect between Axes
701
- # ~~~~~~~~~~~~~~~~~~~~~~~~
736
+ # ^^^^^^^^^^^^^^^^^^^^^^^^
702
737
#
703
738
# `mpl_toolkits.axes_grid1.inset_locator` defines some patch classes useful for
704
739
# interconnecting two axes.
0 commit comments