matplotlib:如何拿起班点击图? [英] matplotlib: How to pick up shift click on figure?
本文介绍了matplotlib:如何拿起班点击图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个matplotlib,并且已经创建了一个 button_press_event
,如下所示:
I have a matplotlib and I have created a button_press_event
like this:
self.fig.canvas.mpl_connect('button_press_event', self.onClick)
def onClick(self, event)
if event.button == 1:
# draw some artists on left click
elif event.button == 2:
# draw a vertical line on the mouse x location on wheel click
elif event.button == 3:
# clear artists on right click
现在可以将滚轮点击处理程序修改为类似的内容
Now is it possible to modify the wheel click handler to something like this
elif event.button == 2 or (event.button == 1 and event.key == "shift"):
# draw a vertical line on the mouse x location
# on wheel click or on shift+left click
# (alternative way if there is no wheel for example)
似乎 button_press_event
不支持键,并且 key_press_event
不支持鼠标单击,但是我不确定.
It seems that button_press_event
doesn't support keys and key_press_event
doesn't support mouse button clicks, but I'm not sure.
有办法吗?
推荐答案
你还可以绑定一个按键按下和按键释放事件,并执行如下操作:
You can also bind a key press and key release events and do something like:
self.fig.canvas.mpl_connect('key_press_event', self.on_key_press)
self.fig.canvas.mpl_connect('key_release_event', self.on_key_release)
...
def on_key_press(self, event):
if event.key == 'shift':
self.shift_is_held = True
def on_key_release(self, event):
if event.key == 'shift':
self.shift_is_held = False
然后,如果 self.shift_is_held
,则可以签入 onClick
函数.
Then you can check in your onClick
function if self.shift_is_held
.
if event.button == 3:
if self.shift_is_held:
do_something()
else:
do_something_else()
这篇关于matplotlib:如何拿起班点击图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文