You are reading an old version of the documentation (v3.1.3). For the latest version see https://matplotlib.org/stable/gallery/pyplots/annotate_transform.html
Version 3.1.3
matplotlib
Fork me on GitHub

Table of Contents

Related Topics

Annotate Transform

This example shows how to use different coordinate systems for annotations. For a complete overview of the annotation capabilities, also see the annotation tutorial.

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 10, 0.005)
y = np.exp(-x/2.) * np.sin(2*np.pi*x)

fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlim(0, 10)
ax.set_ylim(-1, 1)

xdata, ydata = 5, 0
xdisplay, ydisplay = ax.transData.transform_point((xdata, ydata))

bbox = dict(boxstyle="round", fc="0.8")
arrowprops = dict(
    arrowstyle = "->",
    connectionstyle = "angle,angleA=0,angleB=90,rad=10")

offset = 72
ax.annotate('data = (%.1f, %.1f)'%(xdata, ydata),
            (xdata, ydata), xytext=(-2*offset, offset), textcoords='offset points',
            bbox=bbox, arrowprops=arrowprops)


disp = ax.annotate('display = (%.1f, %.1f)'%(xdisplay, ydisplay),
            (xdisplay, ydisplay), xytext=(0.5*offset, -offset),
            xycoords='figure pixels',
            textcoords='offset points',
            bbox=bbox, arrowprops=arrowprops)


plt.show()
../../_images/sphx_glr_annotate_transform_001.png

References

The use of the following functions, methods, classes and modules is shown in this example:

Out:

<function annotate at 0x7f18a5a694c0>

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery