Skip to content

Minor improvements to Annotations Tutorial #24314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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