我正在尝试使用DataCursor方法(
https://stackoverflow.com/a/4674445/1301710)使用matplotlib标记点.我有几千点,并希望在鼠标悬停时看到他们的标签.但是,有两个不同之处:一,我正在制作散点图和两个,我想为每个点标注名称而不仅仅是x,y坐标.
这是我的代码
import os
import matplotlib.pyplot as plt
class DataCursor(object):
text_template = 'x: %0.2f\ny: %0.2f'
x, y = 0.0, 0.0
xoffset, yoffset = -20, 20
text_template = 'x: %0.2f\ny: %0.2f'
def __init__(self, ax, labels,x,y):
self.ax = ax
self.xlist = x
self.ylist = y
self.labels = labels
self.annotation = ax.annotate(self.text_template,
xy=(self.x, self.y), xytext=(self.xoffset, self.yoffset),
textcoords='offset points', ha='right', va='bottom',
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),