picking a broken_barh collection calls pick event twice

If I click on a bar that is part of a broken_barh collection which has its picker attribute enabled, there appears to be two events generated for example:

def on_pick(self, event):
    print event.mouseevent.xdata

    print event.mouseevent.ydata

clicking on a bar will cause this method to be executed twice, hence I get something like this if I click just once:

5575.97222222
0.0277777777778
5575.97222222

0.0277777777778

Is there a workaround such that the method is executed only once?

My guess is that clicking on a collection causes a pick event to be returned by the collection itself and also perhaps by the barh member in the collection. No idea if that’s the case, but just for the record, I figured out a simple enough workaround in which the pick handler is disconnected to open a wxPython popup window. Once that window is closed, the pick handler is reconnected:

self.evt_bind = self.canvas.mpl_connect('pick_event', self.on_pick)
. . . .
def on_pick(self, event):
    if type(event.artist) == brokenbarh:
        self.canvas.mpl_disconnect(self.evt_bind)
        popup = popupwin(self, event.mouseevent.xdata, event.mouseevent.ydata)
        popup.Popup()

class popupwin(wx.PopupTransientWindow):
def init(self, plot, x_coord, y_coord):
wx.PopupTransientWindow.init(self, plot)
self.plot = plot
text = st.gen(self, ‘hello’)

def OnDismiss(self):
    self.plot.evt_bind = self.plot.canvas.mpl_connect('pick_event', self.plot.on_pick
···

On Sun, Jun 22, 2008 at 1:18 AM, Paul Hartley <phartley@…287…> wrote:

If I click on a bar that is part of a broken_barh collection which has its picker attribute enabled, there appears to be two events generated for example:

def on_pick(self, event):
    print event.mouseevent.xdata


    print event.mouseevent.ydata

clicking on a bar will cause this method to be executed twice, hence I get something like this if I click just once:

5575.97222222
0.0277777777778
5575.97222222

0.0277777777778

Is there a workaround such that the method is executed only once?

I am not seeing this with the latest mpl. Here is the example I am
using. For future reference, if you post s complete, self-contained
example we're much more likely to be able to help quickly. If I have
to write the example to see if there is a bug, I'm much more likely to
back-burner it.

from matplotlib.pyplot import figure, show

fig = figure()
ax = fig.add_subplot(111)
ax.broken_barh([ (110, 30), (150, 10) ] , (10, 9), picker=5)
ax.broken_barh([ (10, 50), (100, 20), (130, 10)] , (20, 9),
                facecolors=('red', 'yellow', 'green'), picker=5)

ax.set_ylim(5,35)
ax.set_xlim(0,200)
ax.set_xlabel('seconds since start')
ax.set_yticks([15,25])
ax.set_yticklabels(['Bill', 'Jim'])
ax.grid(True)

def on_pick(event):
    print event.artist, event.mouseevent.xdata, event.mouseevent.ydata

fig.canvas.mpl_connect('pick_event', on_pick)
show()

···

On Sun, Jun 22, 2008 at 3:18 AM, Paul Hartley <phartley@...287...> wrote:

If I click on a bar that is part of a broken_barh collection which has its
picker attribute enabled, there appears to be two events generated for
example:

    def on_pick(self, event):
        print event.mouseevent.xdata
        print event.mouseevent.ydata