开发者

Data value at each marker

开发者 https://www.devze.com 2023-03-14 10:04 出处:网络
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

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

精彩评论

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