pythonmatplotlibattributeerrormplcursors

AttributeError occurs when clicking with mplcursors


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'

Solution