[英]Matplotlib “pick_event” not working in embedded graph with FigureCanvasTkAgg
I'm trying to handle some events to perform user interactions with embedded subplots into a Tkinter frame. 我正在尝试处理一些事件来执行用户与嵌入式子图的交互到Tkinter框架中。 Like in this example
就像在这个例子中
Works fine with "key_press_event" and "button_press_event", but does not work with "pick_event". 使用“key_press_event”和“button_press_event”可以正常工作,但不适用于“pick_event”。
I modified that example from the link, just adding the following piece of code after the mpl_connect
calling: 我在链接中修改了该示例,只需在
mpl_connect
调用后添加以下代码:
def on_button_press(event):
print('you pressed mouse button')
canvas.mpl_connect('button_press_event', on_button_press)
def on_pick(event):
print('you picked:',event.artist)
canvas.mpl_connect('pick_event', on_pick)
Why "pick_event" doesn't work into embedded graphs? 为什么“pick_event”不适用于嵌入式图形? And how do get it to work?
如何让它发挥作用?
My configurations detailed: 我的配置详细:
Thanks in advance! 提前致谢!
Well, I solved it... 好吧,我解决了......
Most events we just need to use mpl_connect
method to the magic happen. 大多数事件我们只需要使用
mpl_connect
方法来实现魔法。 My mistake is that I didn't notice that we need to say explictly that our plot is "pickable" putting a argument picker=True
to only triggers the event if clicked exacly into the artist, and picker=x
where x
is an integer that is the pixel tolerance for the trigger. 我的错误是我没有注意到我们需要明确地说我们的情节是“可选择的”将参数
picker=True
仅在触发事件时触发事件,如果点击进入艺术家,并且picker=x
其中x
是一个整数是触发器的像素容差。 So beyond the changes I inserted for pick in the question, we should replace 因此,除了我在问题中选择的更改,我们应该替换
a.plot(t, s)
for a.plot(t, s,picker=True)
or a.plot(t, s,picker=10)
, eg a.plot(t, s)
, a.plot(t, s,picker=True)
或a.plot(t, s,picker=10)
,例如
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.