| 1 | [Bug]: Attribute Error combining matplotlib 3.7.1 and mplcursor on data selection |
| 2 | ### Bug summary |
| 3 | |
| 4 | If you combine mplcursor and matplotlib 3.7.1, you'll get an `AttributeError: 'NoneType' object has no attribute 'canvas'` after clicking a few data points. Henceforth, selecting a new data point will trigger the same traceback. Otherwise, it works fine. |
| 5 | |
| 6 | ### Code for reproduction |
| 7 | |
| 8 | ```python |
| 9 | import numpy as np |
| 10 | import matplotlib.pyplot as plt |
| 11 | import mplcursors as mpl |
| 12 | |
| 13 | x = np.arange(1, 11) |
| 14 | y1 = x |
| 15 | |
| 16 | plt.scatter(x,y1) |
| 17 | |
| 18 | mpl.cursor() |
| 19 | plt.show() |
| 20 | ``` |
| 21 | |
| 22 | |
| 23 | ### Actual outcome |
| 24 | |
| 25 | ``` |
| 26 | Traceback (most recent call last): |
| 27 | File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 304, in process |
| 28 | func(*args, **kwargs) |
| 29 | File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1550, in on_release |
| 30 | if self._check_still_parented() and self.got_artist: |
| 31 | File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1560, in _check_still_parented |
| 32 | self.disconnect() |
| 33 | File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1568, in disconnect |
| 34 | self.canvas.mpl_disconnect(cid) |
| 35 | File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1517, in <lambda> |
| 36 | canvas = property(lambda self: self.ref_artist.figure.canvas) |
| 37 | AttributeError: 'NoneType' object has no attribute 'canvas' |
| 38 | ``` |
| 39 | |
| 40 | ### Expected outcome |
| 41 | |
| 42 | No terminal output |
| 43 | |
| 44 | ### Additional information |
| 45 | |
| 46 | Using matplotlib 3.7.0 or lower works fine. Using a conda install or pip install doesn't affect the output. |
| 47 | |
| 48 | ### Operating system |
| 49 | |
| 50 | Windows 11 and Windwos 10 |
| 51 | |
| 52 | ### Matplotlib Version |
| 53 | |
| 54 | 3.7.1 |
| 55 | |
| 56 | ### Matplotlib Backend |
| 57 | |
| 58 | QtAgg |
| 59 | |
| 60 | ### Python version |
| 61 | |
| 62 | 3.9.16 |
| 63 | |
| 64 | ### Jupyter version |
| 65 | |
| 66 | _No response_ |
| 67 | |
| 68 | ### Installation |
| 69 | |
| 70 | conda |