Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cf55c1

Browse files
authored
Merge pull request #20744 from QuLogic/cursor-example
Add an example showing alternate mouse cursors.
2 parents 1685bcb + ef94ce4 commit 0cf55c1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

examples/widgets/mouse_cursor.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
============
3+
Mouse Cursor
4+
============
5+
6+
This example sets an alternative cursor on a figure canvas.
7+
8+
Note, this is an interactive example, and must be run to see the effect.
9+
"""
10+
11+
import matplotlib.pyplot as plt
12+
from matplotlib.backend_tools import Cursors
13+
14+
15+
fig, axs = plt.subplots(len(Cursors), figsize=(6, len(Cursors) + 0.5),
16+
gridspec_kw={'hspace': 0})
17+
fig.suptitle('Hover over an Axes to see alternate Cursors')
18+
19+
for cursor, ax in zip(Cursors, axs):
20+
ax.cursor_to_use = cursor
21+
ax.text(0.5, 0.5, cursor.name,
22+
horizontalalignment='center', verticalalignment='center')
23+
ax.set(xticks=[], yticks=[])
24+
25+
26+
def hover(event):
27+
if fig.canvas.widgetlock.locked():
28+
# Don't do anything if the zoom/pan tools have been enabled.
29+
return
30+
31+
fig.canvas.set_cursor(
32+
event.inaxes.cursor_to_use if event.inaxes else Cursors.POINTER)
33+
34+
35+
fig.canvas.mpl_connect('motion_notify_event', hover)
36+
37+
plt.show()
38+
39+
#############################################################################
40+
#
41+
# .. admonition:: References
42+
#
43+
# The use of the following functions, methods, classes and modules is shown
44+
# in this example:
45+
#
46+
# - `matplotlib.backend_bases.FigureCanvasBase.set_cursor`

0 commit comments

Comments
 (0)