Description
I was developing a simple GUI and ran into unexpected behaviour when pressing the number keys 1-9, which disable/enable panning.
Based on the online documentation I was using (http://matplotlib.org/users/navigation_toolbar.html), I wasn't expecting any of the number keys to be used as keyboard shortcuts. However, the key_press_handler method defined in backend_bases.py uses the number keys 1-9 to enable/disable panning on axes (I attached excerpt code below).
I think it would be nice to have these features documented on the webpage, so other developers know that the number keys are used by matplotlib.
Also, here are two thoughts:
- Is the ability to toggle navigation actually needed? (I am not sure what the use-case would be.)
- Assuming the ability to toggle navigation is indeed needed, wouldn't a single button that toggles navigation on given subplot (the one under the cursor) be better? It would (A) free up keyboard shortcuts for other uses and (B) would work when more than 10 subplots are present.
Here's the code from key_press_handler (here's a link https://github.com/matplotlib/matplotlib/blob/v1.3.x/lib/matplotlib/backend_bases.py#L2523)
elif (event.key.isdigit() and event.key != '0') or event.key in all:
# keys in list 'all' enables all axes (default key 'a'),
# otherwise if key is a number only enable this particular axes
# if it was the axes, where the event was raised
if not (event.key in all):
n = int(event.key) - 1
for i, a in enumerate(canvas.figure.get_axes()):
# consider axes, in which the event was raised
# FIXME: Why only this axes?
if event.x is not None and event.y is not None \
and a.in_axes(event):
if event.key in all:
a.set_navigate(True)
else:
a.set_navigate(i == n)