Question

import matplotlib
import matplotlib.pyplot as plt
print matplotlib.__version__
print plt.get_backend()

def key_event(e):
  print e.key

fig = plt.figure()
fig.canvas.mpl_connect('key_press_event', key_event)
plt.show()

I'm interested in key press event handlers with modifiers (e.g. Ctrl, Alt, Shift) in matplotlib/pyplot. This part of the docs mentions some support for modifiers. But when I use the code above I don't see that behaviour.

I would prefer to avoid having to handle the modifiers manually with maintaining state about those key press / release events; for example, I want to be able to easily distinguish between a and ctrl+a without having to maintain a state about control up/down.

-Am I missing some higher level interface somewhere, where modifiers just work?
-Or perhaps that part of the docs only applies to GTKAgg backend, when I generally use TkAgg?
-Maybe the support for modifiers perhaps something which was added recently, and isn't in my matplotlib version 1.1.1rc?

Était-ce utile?

La solution

After seeing mmgp comment above, I tried updating to the repository version, git clone git://github.com/matplotlib/matplotlib.git etc, which gave me 1.3.x. The version in Ubuntu 12.10 is back at 1.1.1rc.

The problem is resolved in the newer version, so it seems to be simply the case that support for modifiers was a recent addition.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top