1

My code to plot and have labeled lines when I hover them keeps getting an error when click on the canvas. I even tried using the basic example from the mplcursors webpage and the same behavior is apparent. If you're going to run the code to see, you may have to click a line and then a blank part of the canvas.

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

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

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.")

mplcursors.cursor(lines)  # or just mplcursors.cursor()

plt.show()

Here is the error I get:

H:\>python C:\Users\m312945\Desktop\Paul\Scripts\Cluster\test_animation_test_mp.py
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\matplotlib\cbook\__init__.py", line 304, in process
    func(*args, **kwargs)
  File "C:\Python39\lib\site-packages\matplotlib\offsetbox.py", line 1550, in on_release
    if self._check_still_parented() and self.got_artist:
  File "C:\Python39\lib\site-packages\matplotlib\offsetbox.py", line 1560, in _check_still_parented
    self.disconnect()
  File "C:\Python39\lib\site-packages\matplotlib\offsetbox.py", line 1568, in disconnect
    self.canvas.mpl_disconnect(cid)
  File "C:\Python39\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'
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Paul K.
  • 13
  • 3
  • Confirming this behavior **in `python 3.11.4`, `matplotlib 3.7.1`, `mplcursors 0.5.1`** in jupyter lab with interactive mode, and from a console window. – Trenton McKinney Sep 02 '23 at 22:33
  • `Python 3.9.13`, `matplotlib 3.7.1`, `mplcursors 0.5.2`. Thanks for confirming! – Paul K. Sep 03 '23 at 00:30
  • You might try with matplotlib 3.7.0 in a different environment – Trenton McKinney Sep 03 '23 at 00:49
  • Matplotlib 3.7.0 worked. I had just found this page, too, which confirmed it wasn't mplcursors causing the issue as I had thought. https://github.com/matplotlib/matplotlib/issues/25440/ – Paul K. Sep 03 '23 at 01:04
  • 1
    Looks like they resolved it in `matplotlib 3.7.2` as well so we're good to go. Thanks for your help. If you make an answer, I will mark it complete. – Paul K. Sep 03 '23 at 01:07

1 Answers1

0
  • GitHub: matplotlib issue 25440 notes this as an issue with matplotlib v3.7.1.
  • The issue is resolved be either using matplotlib v3.7.0, or updating to matplotlib v3.7.2.
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158