Skip to content

[Bug]: Attribute Error combining matplotlib 3.7.1 and mplcursor on data selection #25440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MrAnimaniac opened this issue Mar 12, 2023 · 2 comments · Fixed by #25442
Closed
Milestone

Comments

@MrAnimaniac
Copy link

MrAnimaniac commented Mar 12, 2023

Bug summary

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.

Code for reproduction

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

x = np.arange(1, 11)    
y1 = x

plt.scatter(x,y1)

mpl.cursor()
plt.show()

Actual outcome

Traceback (most recent call last):
  File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 304, in process
    func(*args, **kwargs)
  File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1550, in on_release
    if self._check_still_parented() and self.got_artist:
  File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1560, in _check_still_parented
    self.disconnect()
  File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1568, in disconnect
    self.canvas.mpl_disconnect(cid)
  File "C:\Users\MrAni\Python\miniconda3\lib\site-packages\matplotlib\offsetbox.py", line 1517, in <lambda>
    canvas = property(lambda self: self.ref_artist.figure.canvas)
AttributeError: 'NoneType' object has no attribute 'canvas'

Expected outcome

No terminal output

Additional information

Using matplotlib 3.7.0 or lower works fine. Using a conda install or pip install doesn't affect the output.

Operating system

Windows 11 and Windwos 10

Matplotlib Version

3.7.1

Matplotlib Backend

QtAgg

Python version

3.9.16

Jupyter version

No response

Installation

conda

@jklymak
Copy link
Member

jklymak commented Mar 12, 2023

Can you report to https://github.com/anntzer/mplcursors/issues? I'll close here but feel free to open an issue if a Matplotlib bug is identified.

@anntzer
Copy link
Contributor

anntzer commented Mar 12, 2023

Actually the issue is with Matplotlib, see #25442 and in particular the minimal repro implied by the test added in that PR.

@QuLogic QuLogic added this to the v3.7.2 milestone Mar 13, 2023
@QuLogic QuLogic changed the title [Bug]: Attribute Error combining matplotlib 3.7.1 and mplcursor on data selection [Bug]: Attribute Error combining matplotlib 3.7.1 and mplcursor on data selection Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants