下面是使用两列注释的散点图的代码,用mplcursors
第三列标记点。
如何从单个数据框中的两列中选择两个值作为单个文本框中的注释文本?
当而不是仅"name"
在注释文本框中,我希望两者都"height"
显示"name"
在注释文本框中。使用df[['height', 'name']]
不起作用。
否则如何实现?
df = pd.DataFrame(
[("Alice", 163, 54),
("Bob", 174, 67),
("Charlie", 177, 73),
("Diane", 168, 57)],
columns=["name", "height", "weight"])
df.plot.scatter("height", "weight")
mplcursors.cursor(multiple = True).connect("add", lambda sel: sel.annotation.set_text((df["name"])[sel.target.index]))
plt.show()