Skip to content

Commit e14cc7b

Browse files
authored
Merge pull request #19904 from anntzer/cursor
Don't set zoom/pan cursor for non-navigatable axes.
2 parents d65bb77 + 9e77036 commit e14cc7b

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,11 +3040,7 @@ def _update_cursor(self, event):
30403040
"""
30413041
Update the cursor after a mouse move event or a tool (de)activation.
30423042
"""
3043-
if not event.inaxes or not self.mode:
3044-
if self._lastCursor != cursors.POINTER:
3045-
self.set_cursor(cursors.POINTER)
3046-
self._lastCursor = cursors.POINTER
3047-
else:
3043+
if self.mode and event.inaxes and event.inaxes.get_navigate():
30483044
if (self.mode == _Mode.ZOOM
30493045
and self._lastCursor != cursors.SELECT_REGION):
30503046
self.set_cursor(cursors.SELECT_REGION)
@@ -3053,6 +3049,9 @@ def _update_cursor(self, event):
30533049
and self._lastCursor != cursors.MOVE):
30543050
self.set_cursor(cursors.MOVE)
30553051
self._lastCursor = cursors.MOVE
3052+
elif self._lastCursor != cursors.POINTER:
3053+
self.set_cursor(cursors.POINTER)
3054+
self._lastCursor = cursors.POINTER
30563055

30573056
@contextmanager
30583057
def _wait_cursor_for_draw_cm(self):

lib/matplotlib/backend_tools.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,11 @@ class SetCursorBase(ToolBase):
223223
def __init__(self, *args, **kwargs):
224224
super().__init__(*args, **kwargs)
225225
self._id_drag = None
226-
self._cursor = None
226+
self._current_tool = None
227227
self._default_cursor = cursors.POINTER
228228
self._last_cursor = self._default_cursor
229229
self.toolmanager.toolmanager_connect('tool_added_event',
230230
self._add_tool_cbk)
231-
232231
# process current tools
233232
for tool in self.toolmanager.tools.values():
234233
self._add_tool(tool)
@@ -243,10 +242,9 @@ def set_figure(self, figure):
243242

244243
def _tool_trigger_cbk(self, event):
245244
if event.tool.toggled:
246-
self._cursor = event.tool.cursor
245+
self._current_tool = event.tool
247246
else:
248-
self._cursor = None
249-
247+
self._current_tool = None
250248
self._set_cursor_cbk(event.canvasevent)
251249

252250
def _add_tool(self, tool):
@@ -264,16 +262,14 @@ def _add_tool_cbk(self, event):
264262
def _set_cursor_cbk(self, event):
265263
if not event:
266264
return
267-
268-
if not getattr(event, 'inaxes', False) or not self._cursor:
269-
if self._last_cursor != self._default_cursor:
270-
self.set_cursor(self._default_cursor)
271-
self._last_cursor = self._default_cursor
272-
elif self._cursor:
273-
cursor = self._cursor
274-
if cursor and self._last_cursor != cursor:
275-
self.set_cursor(cursor)
276-
self._last_cursor = cursor
265+
if (self._current_tool and getattr(event, "inaxes", None)
266+
and event.inaxes.get_navigate()):
267+
if self._last_cursor != self._current_tool.cursor:
268+
self.set_cursor(self._current_tool.cursor)
269+
self._last_cursor = self._current_tool.cursor
270+
elif self._last_cursor != self._default_cursor:
271+
self.set_cursor(self._default_cursor)
272+
self._last_cursor = self._default_cursor
277273

278274
def set_cursor(self, cursor):
279275
"""

0 commit comments

Comments
 (0)