You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Callbacks of draggable artists should check that they have not been removed #6785
A minimal mpldatacursor-like module, that adds a single annotation wherever the user left-clicks and removes it upon right click:
from matplotlib import pyplot as plt
fig, ax = plt.subplots()
ann = None
def cb(event):
global ann
if event.button == 1:
if ann:
ann.remove()
ann = ax.annotate("foo", (event.xdata, event.ydata))
fig.canvas.draw()
if event.button == 3:
if ann:
ann.remove()
ann = None
fig.canvas.draw()
fig.canvas.mpl_connect("button_press_event", cb)
plt.show()
If we want to make the annotation also draggable, we could add ann.draggable() after adding it. But then right-clicking to remove the annotation results in
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/matplotlib/backends/backend_qt5.py", line 290, in mouseReleaseEvent
guiEvent=event)
File "/usr/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 1921, in button_release_event
self.callbacks.process(s, event)
File "/usr/lib/python3.5/site-packages/matplotlib/cbook.py", line 550, in process
proxy(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/matplotlib/cbook.py", line 417, in __call__
return mtd(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/matplotlib/offsetbox.py", line 1687, in on_release
self.finalize_offset()
File "/usr/lib/python3.5/site-packages/matplotlib/offsetbox.py", line 1768, in finalize_offset
pos_axes_fraction = self.annotation.axes.transAxes.inverted()
AttributeError: 'NoneType' object has no attribute 'transAxes'
Fatal Python error: Aborted
basically because the button_release callback is called one last time after the annotation has been removed from the axes (and thus annotation.axes is None).
So either the draggable artist should check that it is still valid while executing callback code, or it should disconnect itself upon removal (but there may be some weird race conditions?).
There's at least another issue with the DraggableBase code: the mouse move callback (._c1) does not get disconnected when .disconnect() is called (I tried explicitly calling .disconnect() to work around the above-mentioned issue, but I then get a crash upon moving the mouse because on_motion becomes invalid).
Activity
anntzer commentedon Jul 18, 2016
There's at least another issue with the
DraggableBasecode: the mouse move callback (._c1) does not get disconnected when.disconnect()is called (I tried explicitly calling.disconnect()to work around the above-mentioned issue, but I then get a crash upon moving the mouse becauseon_motionbecomes invalid).anntzer commentedon Sep 2, 2016
Closed by #6808.