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

.. only:: html

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

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

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

.. _sphx_glr_examples_paired_highlight.py:


Linked artists
==============

An example of connecting to cursor events: when an artist is selected, also
highlight its "partner".

.. GENERATED FROM PYTHON SOURCE LINES 8-42



.. image-sg:: /examples/images/sphx_glr_paired_highlight_001.png
   :alt: paired highlight
   :srcset: /examples/images/sphx_glr_paired_highlight_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


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


    def main():
        fig, axes = plt.subplots(ncols=2)
        num = 5
        xy = np.random.random((num, 2))

        lines = []
        for i in range(num):
            line, = axes[0].plot((i + 1) * np.arange(10))
            lines.append(line)

        points = []
        for x, y in xy:
            point, = axes[1].plot([x], [y], linestyle="none", marker="o")
            points.append(point)

        cursor = mplcursors.cursor(points + lines, highlight=True)
        pairs = dict(zip(points, lines))
        pairs.update(zip(lines, points))

        @cursor.connect("add")
        def on_add(sel):
            sel.extras.append(cursor.add_highlight(pairs[sel.artist]))

        plt.show()


    if __name__ == "__main__":
        main()


.. _sphx_glr_download_examples_paired_highlight.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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