有人知道为什么在矩形上使用 mplcursor 悬停时我会在某些点上得到“_line0”吗?我在一个子图中创建了一堆矩形,并使用以下代码创建了一个光标以在将鼠标悬停在它们上时显示注释:
def update_annotation(sel):
""" update the annotation belonging to the current selected item (sel) """
# get the label of the graphical element that is selected
label = sel.artist.get_label()
#point = sel.artist[sel.target.index]
# change the text of the annotation
sel.annotation.set_text(label)
sel.annotation.set(position=(1, 10), anncoords="offset points")
sel.annotation.get_bbox_patch().set(fc="yellow", alpha = 1)
sel.annotation.arrow_patch.set(arrowstyle="simple", fc="yellow", alpha=.5)
# create an mplcursor object that shows an annotation while hovering
cursor = mplcursors.cursor(axs[1], hover=True)
# call the function "update_annotation" each time a new element gets hovered over
cursor.connect("add", update_annotation)
但是,当我将鼠标悬停在某个数据点上时,不仅去我悬停的地方真的很慢,而且它还向我展示了这一点:
我的猜测是重叠的数据点太多了?如果是这样,有没有人知道解决这个问题的方法,也有人可以向我解释 _line0 的含义吗?
我意识到光标悬停在绘图中的空白区域,但当我将鼠标悬停在矩形上时它也显示 _line0。有时它甚至会显示标签然后回到_line0。