
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/units/annotate_with_units.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_units_annotate_with_units.py>`
        to download the full example code.

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

.. _sphx_glr_gallery_units_annotate_with_units.py:


=====================
Annotation with units
=====================

The example illustrates how to create text and arrow
annotations using a centimeter-scale plot.

.. only:: builder_html

   This example requires :download:`basic_units.py <basic_units.py>`

.. GENERATED FROM PYTHON SOURCE LINES 13-38



.. image-sg:: /gallery/units/images/sphx_glr_annotate_with_units_001.png
   :alt: annotate with units
   :srcset: /gallery/units/images/sphx_glr_annotate_with_units_001.png, /gallery/units/images/sphx_glr_annotate_with_units_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python


    from basic_units import cm

    import matplotlib.pyplot as plt

    fig, ax = plt.subplots()

    ax.annotate("Note 01", [0.5*cm, 0.5*cm])

    # xy and text both unitized
    ax.annotate('local max', xy=(3*cm, 1*cm), xycoords='data',
                xytext=(0.8*cm, 0.95*cm), textcoords='data',
                arrowprops=dict(facecolor='black', shrink=0.05),
                horizontalalignment='right', verticalalignment='top')

    # mixing units w/ nonunits
    ax.annotate('local max', xy=(3*cm, 1*cm), xycoords='data',
                xytext=(0.8, 0.95), textcoords='axes fraction',
                arrowprops=dict(facecolor='black', shrink=0.05),
                horizontalalignment='right', verticalalignment='top')


    ax.set_xlim(0*cm, 4*cm)
    ax.set_ylim(0*cm, 4*cm)
    plt.show()


.. _sphx_glr_download_gallery_units_annotate_with_units.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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