Data value at each marker
How can I show the value of each datapoint at each m开发者_运维技巧arker, when plotting with matplotlib.pyplot.plot() ?
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)
精彩评论