Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the keyboard shortcuts in Matplotlib?

I'm working with some event handling in matplotlib. Specifically 'key_press_event's. But the predefined keyboard shortcuts are getting in my way. Is there a way to turn these off?

They say I can override the keys by use of: "matplotlibrc (#keymap.*)". But I don't understand what they're referring to and I haven't found any further explanation.

like image 449
Ben Avatar asked Oct 08 '12 01:10

Ben


People also ask

Can you turn off Keyboard shortcuts?

Select “Keyboard” from the list on the left side of your screen. Click on “Shortcuts” in the list of settings across the top of the window. Once inside “Shortcuts,” uncheck the box next to each shortcut to disable it.

How do I turn off the Keyboard shortcut in Ease of Access Keyboard settings?

In the Settings screen, in the lower-right corner, click Change PC settings. In the PC Settings screen, click Ease of Access. In the Ease of Access screen, click Keyboard. In the Keyboard screen, click the button under Sticky Keys, Filter Keys or Toggle Keys to turn each of those features either On or Off.


2 Answers

You can modify in plt.rcParams dictionary. Example, to disable the "s" keyboard shortcut for the "save figure" button:

>>> plt.rcParams['keymap.save']
['s', 'ctrl+s']
>>> plt.rcParams['keymap.save'].remove('s')

If you want the changes to apply globally/permanently, then edit in the matplotlibrc file and restart the Python interpreter. You may find the location of the config file on your system by calling a helper function:

>>> matplotlib.matplotlib_fname()
'/Users/wim/.matplotlib/matplotlibrc'

Note: In older versions of matplotlib, the keymap bindings were strings rather than lists. If you are stuck on older version, you could set the value to an empty string rather than calling remove.

like image 170
wim Avatar answered Oct 05 '22 03:10

wim


See https://matplotlib.org/users/customizing.html for all keymap keywords that you can use with the above mentioned method, plt.rcParams['keymap.*']

like image 37
Apostolos Avatar answered Oct 05 '22 02:10

Apostolos