Skip to content

Commit

Permalink
Merge pull request #24314 from timhoffm/doc-annotation-tutorial
Browse files Browse the repository at this point in the history
Minor improvements to Annotations Tutorial
  • Loading branch information
timhoffm committed Nov 1, 2022
2 parents de8739f + 484e380 commit 77c33f0
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tutorials/text/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
Annotations
===========
Annotating text with Matplotlib.
Annotations are graphical elements, often pieces of text, that explain, add
context to, or otherwise highlight some portion of the visualized data.
`~.Axes.annotate` supports a number of coordinate systems for flexibly
positioning data and annotations relative to each other and a variety of
options of for styling the text. Axes.annotate also provides an optional arrow
from the text to the data and this arrow can be styled in various ways.
`~.Axes.text` can also be used for simple text annotation, but does not
provide as much flexibility in positioning and styling as `~.Axes.annotate`.
.. contents:: Table of Contents
:depth: 3
Expand All @@ -13,14 +20,9 @@
# Basic annotation
# ----------------
#
# The uses of the basic :func:`~matplotlib.pyplot.text` will place text
# at an arbitrary position on the Axes. A common use case of text is to
# annotate some feature of the plot, and the
# :func:`~matplotlib.axes.Axes.annotate` method provides helper functionality
# to make annotations easy. In an annotation, there are two points to
# consider: the location being annotated represented by the argument
# *xy* and the location of the text *xytext*. Both of these
# arguments are ``(x, y)`` tuples:
# In an annotation, there are two points to consider: the location of the data
# being annotated *xy* and the location of the annotation text *xytext*. Both
# of these arguments are ``(x, y)`` tuples:

import numpy as np
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -177,9 +179,10 @@
# text:

fig, ax = plt.subplots(figsize=(5, 5))
t = ax.text(0, 0, "Direction",
t = ax.text(0.5, 0.5, "Direction",
ha="center", va="center", rotation=45, size=15,
bbox=dict(boxstyle="rarrow,pad=0.3", fc="cyan", ec="b", lw=2))
bbox=dict(boxstyle="rarrow,pad=0.3",
fc="lightblue", ec="steelblue", lw=2))

###############################################################################
# The arguments are the name of the box style with its attributes as
Expand Down

0 comments on commit 77c33f0

Please sign in to comment.