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)
精彩评论