I'm trying to handle some events to perform user interactions with embedded subplots into a Tkinter frame. Like in this example
Works fine with "key_press_event" and "button_press_event", but does not work with "pick_event".
I modified that example from the link, just adding the following piece of code after the mpl_connect
calling:
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? 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. 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. 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)
, e.g.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With