matplotlib 使用mplcursors单击时发生AttributeError

x6yk4ghg  于 2023-10-24  发布在  其他
关注(0)|答案(1)|浏览(148)

我的代码绘制和有标记的线条,当我悬停在画布上时,总是得到一个错误。我甚至尝试使用mplcursors网页的基本示例,同样的行为是显而易见的。如果你要运行代码来查看,你可能必须单击一行,然后画布的空白部分。

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()

下面是我得到的错误:

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'
7uzetpgm

7uzetpgm1#

相关问题