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

Skip to content

Commit 8987d43

Browse files
anntzertacaswell
authored andcommitted
Deprecate toggling axes navigatability using the keyboard.
I made the backend_tools version just point to backend_bases to avoid repeating the deprecation.
1 parent 78f2e40 commit 8987d43

6 files changed

Lines changed: 33 additions & 21 deletions

File tree

doc/api/next_api_changes/deprecations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,12 @@ The following validators, defined in `.rcsetup`, are deprecated:
223223
``validate_ps_papersize``, ``validate_legend_log``. To test whether an rcParam
224224
value would be acceptable, one can test e.g. ``rc = RcParams(); rc[k] = v``
225225
raises an exception.
226+
227+
Toggling axes navigation from the keyboard using "a" and digit keys
228+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
229+
Axes navigation can still be toggled programmatically using
230+
`.Axes.set_navigate`.
231+
232+
The following related APIs are also deprecated:
233+
``backend_tools.ToolEnableAllNavigation``,
234+
``backend_tools.ToolEnableNavigation``, and ``rcParams["keymap.all_axes"]``.

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ def gen_candidates():
602602
_deprecated_remain_as_none = {
603603
'animation.avconv_path': ('3.3',),
604604
'animation.avconv_args': ('3.3',),
605+
'keymap.all_axes': ('3.3',),
605606
}
606607

607608

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ def key_press_handler(event, canvas, toolbar=None):
23212321
grid_minor_keys = rcParams['keymap.grid_minor']
23222322
toggle_yscale_keys = rcParams['keymap.yscale']
23232323
toggle_xscale_keys = rcParams['keymap.xscale']
2324-
all_keys = rcParams['keymap.all_axes']
2324+
all_keys = dict.__getitem__(rcParams, 'keymap.all_axes')
23252325

23262326
# toggle fullscreen mode ('f', 'ctrl + f')
23272327
if event.key in fullscreen_keys:
@@ -2443,6 +2443,10 @@ def _get_uniform_gridstate(ticks):
24432443
for a in canvas.figure.get_axes():
24442444
if (event.x is not None and event.y is not None
24452445
and a.in_axes(event)): # FIXME: Why only these?
2446+
cbook.warn_deprecated(
2447+
"3.3", message="Toggling axes navigation from the "
2448+
"keyboard is deprecated since %(since)s and will be "
2449+
"removed %(removal)s.")
24462450
a.set_navigate(True)
24472451
# enable navigation only for axes with this index (if such an axes exist,
24482452
# otherwise do nothing)
@@ -2452,6 +2456,10 @@ def _get_uniform_gridstate(ticks):
24522456
for i, a in enumerate(canvas.figure.get_axes()):
24532457
if (event.x is not None and event.y is not None
24542458
and a.in_axes(event)): # FIXME: Why only these?
2459+
cbook.warn_deprecated(
2460+
"3.3", message="Toggling axes navigation from the "
2461+
"keyboard is deprecated since %(since)s and will be "
2462+
"removed %(removal)s.")
24552463
a.set_navigate(i == n)
24562464

24572465

lib/matplotlib/backend_tools.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -410,38 +410,34 @@ def trigger(self, sender, event, data=None):
410410
Gcf.destroy_all()
411411

412412

413-
class ToolEnableAllNavigation(ToolBase):
413+
class _ToolEnableAllNavigation(ToolBase):
414414
"""Tool to enable all axes for toolmanager interaction."""
415415

416416
description = 'Enable all axes toolmanager'
417417
default_keymap = mpl.rcParams['keymap.all_axes']
418418

419419
def trigger(self, sender, event, data=None):
420-
if event.inaxes is None:
421-
return
420+
mpl.backend_bases.key_press_handler(event, self.figure.canvas, None)
422421

423-
for a in self.figure.get_axes():
424-
if (event.x is not None and event.y is not None
425-
and a.in_axes(event)):
426-
a.set_navigate(True)
422+
423+
@cbook.deprecated("3.3")
424+
class ToolEnableAllNavigation(_ToolEnableAllNavigation):
425+
pass
427426

428427

429-
class ToolEnableNavigation(ToolBase):
428+
class _ToolEnableNavigation(ToolBase):
430429
"""Tool to enable a specific axes for toolmanager interaction."""
431430

432431
description = 'Enable one axes toolmanager'
433432
default_keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9)
434433

435434
def trigger(self, sender, event, data=None):
436-
if event.inaxes is None:
437-
return
435+
mpl.backend_bases.key_press_handler(event, self.figure.canvas, None)
436+
438437

439-
n = int(event.key) - 1
440-
if n < len(self.figure.get_axes()):
441-
for i, a in enumerate(self.figure.get_axes()):
442-
if (event.x is not None and event.y is not None
443-
and a.in_axes(event)):
444-
a.set_navigate(i == n)
438+
@cbook.deprecated("3.3")
439+
class ToolEnableNavigation(_ToolEnableNavigation):
440+
pass
445441

446442

447443
class _ToolGridBase(ToolBase):
@@ -1089,8 +1085,8 @@ def trigger(self, *args, **kwargs):
10891085
'fullscreen': ToolFullScreen,
10901086
'quit': ToolQuit,
10911087
'quit_all': ToolQuitAll,
1092-
'allnav': ToolEnableAllNavigation,
1093-
'nav': ToolEnableNavigation,
1088+
'allnav': _ToolEnableAllNavigation,
1089+
'nav': _ToolEnableNavigation,
10941090
'xscale': ToolXScale,
10951091
'yscale': ToolYScale,
10961092
'position': ToolCursorPosition,

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ keymap.quit : ctrl+w, cmd+w # close the current figure
467467
keymap.grid : g # switching on/off a grid in current axes
468468
keymap.yscale : l # toggle scaling of y-axes ('log'/'linear')
469469
keymap.xscale : k, L # toggle scaling of x-axes ('log'/'linear')
470-
keymap.all_axes : a # enable all axes
471470

472471
###ANIMATION settings
473472
animation.writer : ffmpeg # MovieWriter 'backend' to use

matplotlibrc.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@
717717
#keymap.grid_minor: G # switching on/off minor grids in current axes
718718
#keymap.yscale: l # toggle scaling of y-axes ('log'/'linear')
719719
#keymap.xscale: k, L # toggle scaling of x-axes ('log'/'linear')
720-
#keymap.all_axes: a # enable all axes
721720
#keymap.copy: ctrl+c, cmd+c # Copy figure to clipboard
722721

723722

0 commit comments

Comments
 (0)