.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/pyplots/annotate_transform.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_pyplots_annotate_transform.py: ================== Annotate Transform ================== This example shows how to use different coordinate systems for annotations. For a complete overview of the annotation capabilities, also see the :doc:`annotation tutorial`. .. GENERATED FROM PYTHON SOURCE LINES 10-44 .. code-block:: default 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((xdata, ydata)) bbox = dict(boxstyle="round", fc="0.8") arrowprops = dict( arrowstyle="->", connectionstyle="angle,angleA=0,angleB=90,rad=10") offset = 72 ax.annotate( f'data = ({xdata:.1f}, {ydata:.1f})', (xdata, ydata), xytext=(-2*offset, offset), textcoords='offset points', bbox=bbox, arrowprops=arrowprops) ax.annotate( f'display = ({xdisplay:.1f}, {ydisplay:.1f})', xy=(xdisplay, ydisplay), xycoords='figure pixels', xytext=(0.5*offset, -offset), textcoords='offset points', bbox=bbox, arrowprops=arrowprops) plt.show() .. image:: /gallery/pyplots/images/sphx_glr_annotate_transform_001.png :alt: annotate transform :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-52 .. admonition:: References The use of the following functions, methods, classes and modules is shown in this example: - `matplotlib.transforms.Transform.transform` - `matplotlib.axes.Axes.annotate` / `matplotlib.pyplot.annotate` .. _sphx_glr_download_gallery_pyplots_annotate_transform.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: annotate_transform.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: annotate_transform.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature Keywords: matplotlib code example, codex, python plot, pyplot `Gallery generated by Sphinx-Gallery `_