I want to label every dot I plot in python, and I didn't find a proper way to do it.
Assuming I have two lists of n elements called a and b, I print them this way :
plt.figure()
plt.grid()
plt.plot(a , b , 'bo')
plt.show()
I want to label every point with "Variable k" with k ranging from 1 to n obviously.
Thanks for your time
解决方案
Here is the best way of doing it I found :
plt.figure()
plt.scatter(a,b)
labels = ['Variable {0}'.format(i+1) for i in range(n)]
for i in range (0,n):
xy=(a[i],b[i])
plt.annotate(labels[i],xy)
plt.plot()