1

I'm having this really weird issue where a pick event is fired if you "scroll" while the mouse cursor is placed over the artist object of interest. Is this expected behaviour? To clarify, I'm using a Macbook, and by scroll I mean the two finger swipe (or one finger on a Magic Mouse).

The functionality I'm trying to achieve is have tooltips on certain axvspan segments (Polygon artist objects), and the pick event works if you click, but even if you scroll while the mouse is over one of the segments of interest, multiple pick events are fired.

I couldn't find anything online where people faced the same issue, and the doc isn't that clear on the firing of a pick event either (It just says: "fired when the user picks a location on the canvas sufficiently close to an artist"). What constitutes a "pick"?

EDIT: An example of what I am doing (these functions are part of a wxpython panel sub-class)

def plot(self):            
    for i 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
        for i in range(len(startTimes)):
            if x < endTimes[i] and x > startTimes[i]:
                print segmentLabels[i]
2
  • Does the same thing happen if you use a real mouse with a scroll wheel? Can you put up a minimal example which demonstrates the problem? Commented Mar 17, 2015 at 13:55
  • Yes it does, I just confirmed. And sure, please see my edit above Commented Mar 17, 2015 at 16:28

1 Answer 1

4

You may now have solved this but for reference the scroll wheel is registered as a button so that is indeed the expected functionality.

A solution to your issue above would be to filter the event using the MouseEvent's button property:

def onpick3(self, event):
    if event.mouseevent.button == 1 # --> Left-click only
        x = event.mouseevent.xdata
        y = event.mouseevent.ydata
        for i in range(len(startTimes)):
            if x < endTimes[i] and x > startTimes[i]:
                print segmentLabels[i]

The documentation is found here:

http://matplotlib.org/api/backend_bases_api.html#matplotlib.backend_bases.MouseEvent

A pick event is fired when the user invokes a MouseEvent (see link above) in a location on the canvas sufficiently close to an artist.

'Sufficiently close' can be controlled by passing an integer as tolerance to the axvspan picker attr, so "picker=True" above, might become "picker=5".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.