|
2 | 2 | Annotations
|
3 | 3 | ===========
|
4 | 4 |
|
5 |
| -Annotating text with Matplotlib. |
| 5 | +Annotations are graphical elements, often pieces of text, that explain, add |
| 6 | +context to, or otherwise highlight some portion of the visualized data. |
| 7 | +`~.Axes.annotate` supports a number of coordinate systems for flexibly |
| 8 | +positioning data and annotations relative to each other and a variety of |
| 9 | +options of for styling the text. Axes.annotate also provides an optional arrow |
| 10 | +from the text to the data and this arrow can be styled in various ways. |
| 11 | +`~.Axes.text` can also be used for simple text annotation, but does not |
| 12 | +provide as much flexibility in positioning and styling as `~.Axes.annotate`. |
6 | 13 |
|
7 | 14 | .. contents:: Table of Contents
|
8 | 15 | :depth: 3
|
|
13 | 20 | # Basic annotation
|
14 | 21 | # ----------------
|
15 | 22 | #
|
16 |
| -# The uses of the basic :func:`~matplotlib.pyplot.text` will place text |
17 |
| -# at an arbitrary position on the Axes. A common use case of text is to |
18 |
| -# annotate some feature of the plot, and the |
19 |
| -# :func:`~matplotlib.axes.Axes.annotate` method provides helper functionality |
20 |
| -# to make annotations easy. In an annotation, there are two points to |
21 |
| -# consider: the location being annotated represented by the argument |
22 |
| -# *xy* and the location of the text *xytext*. Both of these |
23 |
| -# arguments are ``(x, y)`` tuples: |
| 23 | +# In an annotation, there are two points to consider: the location of the data |
| 24 | +# being annotated *xy* and the location of the annotation text *xytext*. Both |
| 25 | +# of these arguments are ``(x, y)`` tuples: |
24 | 26 |
|
25 | 27 | import numpy as np
|
26 | 28 | import matplotlib.pyplot as plt
|
|
177 | 179 | # text:
|
178 | 180 |
|
179 | 181 | fig, ax = plt.subplots(figsize=(5, 5))
|
180 |
| -t = ax.text(0, 0, "Direction", |
| 182 | +t = ax.text(0.5, 0.5, "Direction", |
181 | 183 | ha="center", va="center", rotation=45, size=15,
|
182 |
| - bbox=dict(boxstyle="rarrow,pad=0.3", fc="cyan", ec="b", lw=2)) |
| 184 | + bbox=dict(boxstyle="rarrow,pad=0.3", |
| 185 | + fc="lightblue", ec="steelblue", lw=2)) |
183 | 186 |
|
184 | 187 | ###############################################################################
|
185 | 188 | # The arguments are the name of the box style with its attributes as
|
|
0 commit comments