matplotlib を使用して同じプロットでグラフ化する 2 つのデータ セットがあります。ラベル配列を使用して各ポイントに注釈を付けるために、mplcursors を使用しています。残念ながら、mplcursors は両方のデータ セットに最初の 5 つのラベルを使用します。私の質問は、2 番目のデータ セットに独自のカスタム ラベルを持たせるにはどうすればよいですか?
この単純な例ではデータをマージできますが、現在取り組んでいるプロジェクトではできません。
import matplotlib.pyplot as plt
import mplcursors
import numpy as np
x = np.array([0, 1, 2, 3, 4])
y = np.array([1, 2, 3, 4, 5])
y2 = np.array([2, 3, 4, 5, 6])
fig, ax = plt.subplots()
ax.plot(x, y, "ro")
ax.plot(x, y2, 'bx')
labels = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
mplcursors.cursor(ax, hover=True).connect(
"add", lambda sel: sel.annotation.set_text(labels[sel.target.index]))
plt.show()