

.. _sphx_glr_gallery_pyplots_annotate_transform.py:


==================
Annotate Transform
==================





.. image:: /gallery/pyplots/images/sphx_glr_annotate_transform_001.png
    :align: center





.. code-block:: python

    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 = plt.figure()
    ax = fig.add_subplot(111)
    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()

**Total running time of the script:** ( 0 minutes  0.023 seconds)



.. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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

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

    `Generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
