8000 Add an example showing alternate mouse cursors. by QuLogic · Pull Request #20744 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add an example showing alternate mouse cursors. #20744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions examples/widgets/mouse_cursor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
============
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.
"""

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()

#############################################################################
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.backend_bases.FigureCanvasBase.set_cursor`
0