开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜