简体   繁体   English

从txt文件中绘制数据

[英]plot data from a txt file

hi i want to plot this from txt file to a graph 嗨,我想将其从txt文件绘制到图形

13/7/2009 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 will be the x axis and the other columns will be the y axis(in Separate lines) 日期将是x轴,其他列将是y轴(在单独的行中)

thanks pol 谢谢波尔

. .

one of the best python package for plotting data is matplotlib . matplotlib是用于绘制数据的最佳python软件包之一。

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... 然后使用matplotlib绘制数据...

(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) (上面的解析代码可以使用列表理解来重写,这可能会提高内存效率,因为它将隐式使用迭代器和惰性计算,而不是将整个数据存储在列表中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM