:orphan:

.. _examples:

:mod:`mplcursors` examples
==========================

As `mplcursors` is fundamentally a library for interactivity, you should
download the examples and try them yourself :-)

.. vim: ft=rst



.. raw:: html

    <div class="sphx-glr-thumbnails">

.. thumbnail-parent-div-open

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="... is to add interactive data cursors to a figure.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_basic_thumb.png
    :alt:

  :ref:`sphx_glr_examples_basic.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">mplcursors' core functionality</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="When hover is set to True, annotations are displayed when the mouse hovers over the artist, without the need for clicking.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_hover_thumb.png
    :alt:

  :ref:`sphx_glr_examples_hover.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Annotate on hover</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Use an event handler to customize the popup.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_change_popup_color_thumb.png
    :alt:

  :ref:`sphx_glr_examples_change_popup_color.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Changing properties of the popup</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Picking contour plots is supported on Matplotlib≥3.8.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_contour_thumb.png
    :alt:

  :ref:`sphx_glr_examples_contour.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Contour plots</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="... display the underlying data value.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_image_thumb.png
    :alt:

  :ref:`sphx_glr_examples_image.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Cursors on images</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="mplcursors correctly formats datetime data.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_date_thumb.png
    :alt:

  :ref:`sphx_glr_examples_date.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Datetime data</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Using an event handler to change the annotation text and position.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_bar_thumb.png
    :alt:

  :ref:`sphx_glr_examples_bar.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Display a bar's height and name on top of it upon hovering</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Use an event handler to change the annotation text.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_artist_labels_thumb.png
    :alt:

  :ref:`sphx_glr_examples_artist_labels.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Display an artist's label instead of x, y coordinates</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="mpldatacursor&#x27;s point_labels functionality can be emulated with an event handler that sets the annotation text with a label selected from the target index.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_labeled_points_thumb.png
    :alt:

  :ref:`sphx_glr_examples_labeled_points.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Displaying a custom label for each individual point</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="DataFrame\s can be used similarly to any other kind of input. Here, we generate a scatter plot using two columns and label the points using all columns.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_dataframe_thumb.png
    :alt:

  :ref:`sphx_glr_examples_dataframe.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Extracting data and labels from a DataFrame</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Just pass highlight=True to cursor.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_highlight_thumb.png
    :alt:

  :ref:`sphx_glr_examples_highlight.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Highlighting the artist upon selection</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="By default, mplcursors uses &quot;t&quot; to toggle interactivity and &quot;d&quot; to hide/show annotation boxes.  These shortcuts can be customized.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_keyboard_shortcuts_thumb.png
    :alt:

  :ref:`sphx_glr_examples_keyboard_shortcuts.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Keyboard shortcuts</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="An example of connecting to cursor events: when an artist is selected, also highlight its &quot;partner&quot;.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_paired_highlight_thumb.png
    :alt:

  :ref:`sphx_glr_examples_paired_highlight.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Linked artists</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="... as opposed to lines with a &quot;.&quot; style, which have the same appearance, but are highlighted as a whole.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_scatter_thumb.png
    :alt:

  :ref:`sphx_glr_examples_scatter.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Scatter plots are highlighted point-by-point.</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A selection on a step plot holds precise information on the x and y position in the sel.index attribute.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_step_thumb.png
    :alt:

  :ref:`sphx_glr_examples_step.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Step plots</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="By default, each Cursor will ever display one annotation at a time.  Pass multiple=True to display multiple annotations.">

.. only:: html

  .. image:: /examples/images/thumb/sphx_glr_nondraggable_thumb.png
    :alt:

  :ref:`sphx_glr_examples_nondraggable.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Using multiple annotations and disabling draggability via signals</div>
    </div>


.. thumbnail-parent-div-close

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/basic
   /examples/hover
   /examples/change_popup_color
   /examples/contour
   /examples/image
   /examples/date
   /examples/bar
   /examples/artist_labels
   /examples/labeled_points
   /examples/dataframe
   /examples/highlight
   /examples/keyboard_shortcuts
   /examples/paired_highlight
   /examples/scatter
   /examples/step
   /examples/nondraggable


.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-gallery

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

      :download:`Download all examples in Python source code: examples_python.zip </examples/examples_python.zip>`

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

      :download:`Download all examples in Jupyter notebooks: examples_jupyter.zip </examples/examples_jupyter.zip>`


.. only:: html

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

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