1
- .. _plotting-guide-annotation :
1
+ ============
2
+ Annotation
3
+ ============
4
+
5
+ .. contents :: Table of Contents
6
+ :depth: 3
7
+
8
+ .. _annotations-tutorial :
9
+
10
+ Basic annotation
11
+ ================
12
+
13
+ The uses of the basic :func: `~matplotlib.pyplot.text ` command above
14
+ place text at an arbitrary position on the Axes. A common use case of
15
+ text is to annotate some feature of the plot, and the
16
+ :func: `~matplotlib.Axes.annotate ` method provides helper functionality
17
+ to make annotations easy. In an annotation, there are two points to
18
+ consider: the location being annotated represented by the argument
19
+ ``xy `` and the location of the text ``xytext ``. Both of these
20
+ arguments are ``(x,y) `` tuples.
21
+
22
+ .. plot :: pyplots/annotation_basic.py
23
+ :include-source:
24
+
25
+
26
+ In this example, both the ``xy `` (arrow tip) and ``xytext `` locations
27
+ (text location) are in data coordinates. There are a variety of other
28
+ coordinate systems one can choose -- you can specify the coordinate
29
+ system of ``xy `` and ``xytext `` with one of the following strings for
30
+ ``xycoords `` and ``textcoords `` (default is 'data')
31
+
32
+ ==================== ====================================================
33
+ argument coordinate system
34
+ ==================== ====================================================
35
+ 'figure points' points from the lower left corner of the figure
36
+ 'figure pixels' pixels from the lower left corner of the figure
37
+ 'figure fraction' 0,0 is lower left of figure and 1,1 is upper right
38
+ 'axes points' points from lower left corner of axes
39
+ 'axes pixels' pixels from lower left corner of axes
40
+ 'axes fraction' 0,0 is lower left of axes and 1,1 is upper right
41
+ 'data' use the axes data coordinate system
42
+ ==================== ====================================================
43
+
44
+ For example to place the text coordinates in fractional axes
45
+ coordinates, one could do::
46
+
47
+ ax.annotate('local max', xy=(3, 1), xycoords='data',
48
+ xytext=(0.8, 0.95), textcoords='axes fraction',
49
+ arrowprops=dict(facecolor='black', shrink=0.05),
50
+ horizontalalignment='right', verticalalignment='top',
51
+ )
52
+
53
+ For physical coordinate systems (points or pixels) the origin is the
54
+ (bottom, left) of the figure or axes. If the value is negative,
55
+ however, the origin is from the (right, top) of the figure or axes,
56
+ analogous to negative indexing of sequences.
57
+
58
+ Optionally, you can specify arrow properties which draws an arrow
59
+ from the text to the annotated point by giving a dictionary of arrow
60
+ properties in the optional keyword argument ``arrowprops ``.
61
+
62
+
63
+ ==================== =====================================================
64
+ ``arrowprops `` key description
65
+ ==================== =====================================================
66
+ width the width of the arrow in points
67
+ frac the fraction of the arrow length occupied by the head
68
+ headwidth the width of the base of the arrow head in points
69
+ shrink move the tip and base some percent away from
70
+ the annotated point and text
71
+
72
+ \*\*kwargs any key for :class:`matplotlib.patches.Polygon`,
73
+ e.g., ``facecolor ``
74
+ ==================== =====================================================
75
+
76
+
77
+ In the example below, the ``xy `` point is in native coordinates
78
+ (``xycoords `` defaults to 'data'). For a polar axes, this is in
79
+ (theta, radius) space. The text in this example is placed in the
80
+ fractional figure coordinate system. :class: `matplotlib.text.Text `
81
+ keyword args like ``horizontalalignment ``, ``verticalalignment `` and
82
+ ``fontsize are passed from the `~matplotlib.Axes.annotate` to the
83
+ ``Text `` instance
84
+
85
+ .. plot :: pyplots/annotation_polar.py
86
+ :include-source:
87
+
88
+ For more on all the wild and wonderful things you can do with
89
+ annotations, including fancy arrows, see :ref: `plotting-guide-annotation `
90
+ and :ref: `pylab_examples-annotation_demo `.
2
91
3
- ****************
4
- Annotating Axes
5
- ****************
6
92
7
93
Do not proceed unless you already have read :ref: `annotations-tutorial `,
8
94
:func: `~matplotlib.pyplot.text ` and
9
95
:func: `~matplotlib.pyplot.annotate `!
10
96
11
97
98
+ .. _plotting-guide-annotation :
99
+
100
+ Advanced Annotation
101
+ ===================
12
102
13
103
14
104
Annotating with Text with Box
15
- =============================
105
+ -----------------------------
16
106
17
107
Let's start with a simple example.
18
108
@@ -70,7 +160,7 @@ of bbox argument when initializing the text instance) ::
70
160
71
161
72
162
Annotating with Arrow
73
- =====================
163
+ ---------------------
74
164
75
165
The :func: `~matplotlib.pyplot.annotate ` function in the pyplot module
76
166
(or annotate method of the Axes class) is used to draw an arrow
@@ -189,7 +279,7 @@ lower-left corner and (1,1) means top-right.
189
279
190
280
191
281
Placing Artist at the anchored location of the Axes
192
- ===================================================
282
+ ---------------------------------------------------
193
283
194
284
There are class of artist that can be placed at the anchored location
195
285
of the Axes. A common example is the legend. This type of artists can
@@ -264,7 +354,7 @@ Note that unlike the legend, the ``bbox_transform`` is set
264
354
to IdentityTransform by default.
265
355
266
356
Using Complex Coordinate with Annotation
267
- ========================================
357
+ ----------------------------------------
268
358
269
359
The Annotation in matplotlib support several types of coordinate as
270
360
described in :ref: `annotations-tutorial `. For an advanced user who wants
@@ -343,7 +433,7 @@ more control, it supports a few other options.
343
433
You may take a look at this example :ref: `pylab_examples-annotation_demo3 `.
344
434
345
435
Using ConnectorPatch
346
- ====================
436
+ --------------------
347
437
348
438
The ConnectorPatch is like an annotation without a text. While the
349
439
annotate function is recommended in most of situation, the
@@ -370,10 +460,10 @@ drawing order to prevent overlap (?) by other axes.
370
460
371
461
372
462
Advanced Topics
373
- ***************
463
+ ~~~~~~~~~~~~~~~
374
464
375
465
Zoom effect between Axes
376
- ========================
466
+ ------------------------
377
467
378
468
mpl_toolkits.axes_grid.inset_locator defines some patch classes useful
379
469
for interconnect two axes. Understanding the code requires some
@@ -385,7 +475,7 @@ straight forward.
385
475
386
476
387
477
Define Custom BoxStyle
388
- ======================
478
+ ----------------------
389
479
390
480
You can use a custom box style. The value for the ``boxstyle `` can be a
391
481
callable object in following forms.::
0 commit comments