

.. _sphx_glr_examples_change_popup_color.py:


Changing properties of the popup
================================

Use an event handler to customize the popup.




.. image:: /examples/images/sphx_glr_change_popup_color_001.png
    :align: center





.. code-block:: python


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

    fig, axes = plt.subplots(ncols=2)

    left_artist = axes[0].plot(range(11))
    axes[0].set(title="No box, different position", aspect=1)

    right_artist = axes[1].imshow(np.arange(100).reshape(10, 10))
    axes[1].set(title="Fancy white background")

    # Make the text pop up "underneath" the line and remove the box...
    c1 = mplcursors.cursor(left_artist)
    @c1.connect("add")
    def _(sel):
        sel.annotation.set(position=(15, -15))
        # Note: Needs to be set separately due to matplotlib/matplotlib#8956.
        sel.annotation.set_bbox(None)

    # Make the box have a white background with a fancier connecting arrow
    c2 = mplcursors.cursor(right_artist)
    @c2.connect("add")
    def _(sel):
        sel.annotation.get_bbox_patch().set(fc="white")
        sel.annotation.arrow_patch.set(arrowstyle="simple", fc="white", alpha=.5)

    plt.show()



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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