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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_gallery_widgets_mouse_cursor.py>`
        to download the full example code

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

.. _sphx_glr_gallery_widgets_mouse_cursor.py:


============
Mouse Cursor
============

This example sets an alternative cursor on a figure canvas.

Note, this is an interactive example, and must be run to see the effect.

.. GENERATED FROM PYTHON SOURCE LINES 10-39

.. code-block:: default


    import matplotlib.pyplot as plt
    from matplotlib.backend_tools import Cursors


    fig, axs = plt.subplots(len(Cursors), figsize=(6, len(Cursors) + 0.5),
                            gridspec_kw={'hspace': 0})
    fig.suptitle('Hover over an Axes to see alternate Cursors')

    for cursor, ax in zip(Cursors, axs):
        ax.cursor_to_use = cursor
        ax.text(0.5, 0.5, cursor.name,
                horizontalalignment='center', verticalalignment='center')
        ax.set(xticks=[], yticks=[])


    def hover(event):
        if fig.canvas.widgetlock.locked():
            # Don't do anything if the zoom/pan tools have been enabled.
            return

        fig.canvas.set_cursor(
            event.inaxes.cursor_to_use if event.inaxes else Cursors.POINTER)


    fig.canvas.mpl_connect('motion_notify_event', hover)

    plt.show()




.. image-sg:: /gallery/widgets/images/sphx_glr_mouse_cursor_001.png
   :alt: Hover over an Axes to see alternate Cursors
   :srcset: /gallery/widgets/images/sphx_glr_mouse_cursor_001.png, /gallery/widgets/images/sphx_glr_mouse_cursor_001_2_0x.png 2.0x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 40-46

.. admonition:: References

   The use of the following functions, methods, classes and modules is shown
   in this example:

   - `matplotlib.backend_bases.FigureCanvasBase.set_cursor`


.. _sphx_glr_download_gallery_widgets_mouse_cursor.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
