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

.. only:: html

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

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

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

.. _sphx_glr_examples_labeled_points.py:


Displaying a custom label for each individual point
===================================================

mpldatacursor's *point_labels* functionality can be emulated with an event
handler that sets the annotation text with a label selected from the target
index.

.. GENERATED FROM PYTHON SOURCE LINES 9-23



.. image-sg:: /examples/images/sphx_glr_labeled_points_001.png
   :alt: labeled points
   :srcset: /examples/images/sphx_glr_labeled_points_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    import mplcursors
    import numpy as np

    labels = ["a", "b", "c", "d", "e"]
    x = np.array([0, 1, 2, 3, 4])

    fig, ax = plt.subplots()
    line, = ax.plot(x, x, "ro")
    mplcursors.cursor(ax).connect(
        "add", lambda sel: sel.annotation.set_text(labels[sel.index]))

    plt.show()


.. _sphx_glr_download_examples_labeled_points.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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