我有一些数据要绘制在散点图上,并显示每个点的相关标签。数据看起来像这样
xlist=[1,2,3,4]
ylist=[2,3,4,5]
labels=['a', 'b', 'c', 'd']我可以使用Seaborn绘制,并尝试使用mplcursor,但显示的标签是x和y,而不是标签。
sns.scatterplot(x, y)
mplcursors.cursor(hover=True)我怎么才能让它显示标签,而不是(x, y)
发布于 2019-04-24 09:22:33
您需要阅读the mplcursors documentation并将有关该问题的示例复制到您的代码中。让我来为你做一下:
import matplotlib.pyplot as plt
import seaborn as sns
import mplcursors
xlist=[1,2,3,4]
ylist=[2,3,4,5]
labels=['a', 'b', 'c', 'd']
sns.scatterplot(xlist, ylist)
cursor = mplcursors.cursor(hover=True)
cursor.connect(
"add", lambda sel: sel.annotation.set_text(labels[sel.target.index]))
plt.show()https://stackoverflow.com/questions/55820813
复制相似问题