Просто, если кому-то интересно, я нашел какое-то объяснение, но не реальное решение.Ниже приведен код исполнителя, каждый раз, когда вызывается self.figure.canvas.pick_event, событие запускает обратный вызов.По сути, эта рекурсия проходит по всем элементам фигуры, поэтому на самом деле верно, что если вы выбрали несколько точек, обратный вызов будет выполняться несколько раз.
Как с этим справиться?Я полагаю, вам следует переписать некоторый код из matplotlib.Я думаю, что моя версия слишком старая, она 1. что-то.Возможно, более новая версия уже внесла некоторые изменения.
def pick(self, mouseevent):
"""
call signature::
pick(mouseevent)
each child artist will fire a pick event if *mouseevent* is over
the artist and the artist has picker set
"""
# Pick self
if self.pickable():
picker = self.get_picker()
if six.callable(picker):
inside, prop = picker(self, mouseevent)
else:
inside, prop = self.contains(mouseevent)
if inside:
self.figure.canvas.pick_event(mouseevent, self, **prop)
# Pick children
for a in self.get_children():
# make sure the event happened in the same axes
ax = getattr(a, 'axes', None)
if mouseevent.inaxes is None or ax is None or \
mouseevent.inaxes == ax:
# we need to check if mouseevent.inaxes is None
# because some objects associated with an axes (e.g., a
# tick label) can be outside the bounding box of the
# axes and inaxes will be None
# also check that ax is None so that it traverse objects
# which do no have an axes property but children might
a.pick(mouseevent)