我想使用 mplcursors 在同一个工具提示上显示带有标签信息的 x 和 y 值。实际上我使用了两个光标,但框信息重叠。这是我的代码示例:
from matplotlib import pyplot as plt
import mplcursors
from pandas import DataFrame
df = DataFrame(
[("Alice", 163, 54),
("Bob", 174, 67),
("Charlie", 177, 73),
("Diane", 168, 57)],
columns=["name", "height", "weight"])
scatter1=df.plot.scatter("height", "weight")
c1=mplcursors.cursor(scatter1)
mplcursors.cursor().connect(
"add", lambda sel: sel.annotation.set_text(df["name"][sel.target.index]))
plt.show()