Reputation: 1277
How can I show the value of each datapoint at each marker, when plotting with matplotlib.pyplot.plot() ?
Upvotes: 3
Views: 3960
Reputation: 1797
Create a function to add the labels to a given line
import matplotlib
def add_labels(line):
x,y=line.get_data()
labels=map(','.join,zip(map(lambda s: '%g'%s,x),map(lambda s: '%g'%s,y)))
map(matplotlib.pyplot.text,x,y,labels)
Example usage
x=[2,5,7,10]
y=[3.3,5.6,2.1,-.5]
line,= matplotlib.pyplot.plot(x,y)
add_labels(line)
Upvotes: 1