Skip to content

Commit 77c33f0

Browse files
authored
Merge pull request #24314 from timhoffm/doc-annotation-tutorial
Minor improvements to Annotations Tutorial
2 parents de8739f + 484e380 commit 77c33f0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

tutorials/text/annotations.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
Annotations
33
===========
44
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`.
613
714
.. contents:: Table of Contents
815
:depth: 3
@@ -13,14 +20,9 @@
1320
# Basic annotation
1421
# ----------------
1522
#
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:
2426

2527
import numpy as np
2628
import matplotlib.pyplot as plt
@@ -177,9 +179,10 @@
177179
# text:
178180

179181
fig, ax = plt.subplots(figsize=(5, 5))
180-
t = ax.text(0, 0, "Direction",
182+
t = ax.text(0.5, 0.5, "Direction",
181183
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))
183186

184187
###############################################################################
185188
# The arguments are the name of the box style with its attributes as

0 commit comments

Comments
 (0)