尾部读取不断增长的动态文件并提取两列,然后打印图形

use*_*374 4 python graph tail matplotlib

读取1 GB文件的最佳方法是在其中记录时间序列数据,并生成包含两列(一次和其他数字)的实时图表?我看到你有不同的方法来拖尾文件.

Joh*_*ett 7

RRDTool来说听起来不错.

但是如果你想坚持使用Python,我会使用tail将数据流式传输到我的程序中(这假设文件是​​连续写入的,否则Python中的直接打开()将起作用).

tail -F data.log | python myprogram.py
Run Code Online (Sandbox Code Playgroud)

myprogram.py看起来像:

import sys

p = ... # create a pylab plot instance 
for line in sys.stdin:
    elements = line.split(',') # or whatever separator your file has in it
    p.add(element[0], element[1]) # add data to the pylab plot instance
Run Code Online (Sandbox Code Playgroud)