
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/text_labels_and_annotations/annotate_transform.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_text_labels_and_annotations_annotate_transform.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_text_labels_and_annotations_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
:ref:`annotation tutorial<annotations>`.

.. redirect-from:: /gallery/pyplots/annotate_transform

.. GENERATED FROM PYTHON SOURCE LINES 12-46

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np

    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-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_annotate_transform_001.png
   :alt: annotate transform
   :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_annotate_transform_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_annotate_transform_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 47-54

.. 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_text_labels_and_annotations_annotate_transform.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: annotate_transform.ipynb <annotate_transform.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: annotate_transform.py <annotate_transform.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: annotate_transform.zip <annotate_transform.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
