开发者

plot data from a txt file

开发者 https://www.devze.com 2023-04-11 22:48 出处:网络
I would like to plot data from a txt file to a graph: 13/7/20开发者_Go百科09 12:50:50147425826 0 4716298 36645030 3757926 228230

I would like to plot data from a txt file to a graph:

13/7/20开发者_Go百科09 12:50:50   147425826 0 4716298 36645030 3757926 228230
13/7/2009 13:5:1     147517368 0 4717954 36687455 3761270 228375
13/7/2009 13:10:0    147550312 0 4718599 36701448 3762634 228437

The date should be the x axis and the remaining columns should be the y axis (in separated lines).


one of the best python package for plotting data is matplotlib.

then, you only have to parse your input file:

import time

data = []
for line in open('input.txt'):
    date,time,*samples = line.split()
    data.append((time.strptime(str.join(' ', (date, time)), '%d/%m/%Y %H:%M:%S'), samples))

then use matplotlib to plot the data...

(the above parsing code may be rewritten using a list comprehension, which may be more memory efficient since it will implicitly use iterators and lazy evaluation instead of storing the whole data in the list)

0

精彩评论

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