python - Matplotlib Pick Event Functionality -
i'm having weird issue pick event fired if "scroll" while mouse cursor placed on artist object of interest. expected behaviour? clarify, i'm using macbook, , scroll mean 2 finger swipe (or 1 finger on magic mouse).
the functionality i'm trying achieve have tooltips on axvspan segments (polygon artist objects), , pick event works if click, if scroll while mouse on 1 of segments of interest, multiple pick events fired.
i couldn't find online people faced same issue, , doc isn't clear on firing of pick event either (it says: "fired when user picks location on canvas sufficiently close artist"). constitutes "pick"?
edit: example of doing (these functions part of wxpython panel sub-class)
def plot(self): in range(len(starttimes)): self.axs.axvspan(starttimes[i], endtimes[i], color='blue', alpha=0.3, picker=true)) self.figure.canvas.mpl_connect('pick_event', self.onpick3) def onpick3(self, event): x = event.mouseevent.xdata y = event.mouseevent.ydata in range(len(starttimes)): if x < endtimes[i] , x > starttimes[i]: print segmentlabels[i]
you may have solved reference scroll wheel registered button indeed expected functionality.
a solution issue above filter event using mouseevent's button property:
def onpick3(self, event): if event.mouseevent.button == 1 # --> left-click x = event.mouseevent.xdata y = event.mouseevent.ydata in range(len(starttimes)): if x < endtimes[i] , x > starttimes[i]: print segmentlabels[i]
the documentation found here:
http://matplotlib.org/api/backend_bases_api.html#matplotlib.backend_bases.mouseevent
a pick event fired when user invokes mouseevent (see link above) in location on canvas sufficiently close artist.
'sufficiently close' can controlled passing integer tolerance axvspan picker attr, "picker=true" above, might become "picker=5".
Comments
Post a Comment