I am using mplcursors module to show label value. I also want to show the index number from given lists for that particular point on which I will hover.
My Example Code snippet:
import matplotlib.pyplot as plt
import mplcursors
lines = plt.plot([1, 2, 3, 4], [2, 4, 6, 10])
plt.ylabel('some numbers')
mplcursors.cursor(hover=True)
plt.show()
Is there any way that I can use the mplcursors to annotate the required information(as its easy)?
Thanks :)
mplcursorsallows to specify a function that is called every time just before an annotation is shown. That function gets a parameterselwhich among others has atargetfield. In case of a "line", apart from the xy value, the target contains anindex. The integer part of theindexis an index into thexandyarrays of the left end of the segment the cursor is on. The fractional part of theindextells how far we are between the left and the right end of the segment.