anntzer / mplcursors

Interactive data selection cursors for Matplotlib.
https://mplcursors.readthedocs.io
zlib License
113 stars 19 forks source link

Remove a cursor more than once ? #70

Closed arnaudrichard closed 8 months ago

arnaudrichard commented 8 months ago

In my JupyterLab environement, I am not able to remove more than once a cursor (using default right-click binding). I mean the first cursor created with a left-click can be removed with a right-click, but after that, next cursors created can't be removed anymore. Is it due to JupyterLab environement or a mplcursors issue?

I tried with the following example:

import matplotlib.pyplot as plt
import numpy as np
import mplcursors

data = np.outer(range(10), 1)

fig, ax = plt.subplots()
lines = ax.plot(data)
ax.set_title("Click somewhere on a line.\nRight-click to deselect.\n"
             "Annotations can be dragged.")
fig.tight_layout()

mplcursors.cursor(lines, multiple=True)

plt.show()
anntzer commented 8 months ago

As far as I can see this works in a plain terminal ipython for me, can you give it a try and confirm?

arnaudrichard commented 8 months ago

Yes and no: from ipython interpreter, the cursors are deleted, but after I deleted the first one, everytime mouse pointer move there's this error printed in the interpreter:

Traceback (most recent call last): File "C:\Users\richarda\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\cbook__init__.py", line 304, in process func(*args, **kwargs) File "C:\Users\richarda\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\offsetbox.py", line 1520, in on_motion if self._check_still_parented() and self.got_artist: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\richarda\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\offsetbox.py", line 1560, in _check_still_parented self.disconnect() File "C:\Users\richarda\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\offsetbox.py", line 1568, in disconnect self.canvas.mpl_disconnect(cid) ^^^^^^^^^^^ File "C:\Users\richarda\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\offsetbox.py", line 1517, in canvas = property(lambda self: self.ref_artist.figure.canvas) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'canvas'

Is it linked or a completely different issue?

anntzer commented 8 months ago

What are your versions of matplotlib and mplcursors?

arnaudrichard commented 8 months ago

Name: matplotlib Version: 3.7.1 Name: mplcursors Version: 0.5.2

anntzer commented 8 months ago

Ah yes, there's a known bug in matplotlib 3.7.1 that makes cursor removal problematic (https://github.com/matplotlib/matplotlib/issues/25440). I should make a new release that explicitly checks against that version of matplotlib, but in the meantime you should just update (or downgrade) matplotlib.

anntzer commented 8 months ago

Released 0.5.3.

arnaudrichard commented 8 months ago

I confirm upgrading matplotlib solved the issue. Thx !