Hi all, How do I use animation.FuncAnimation to plot real-life data from parsing a text file ?
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import sys import time import re x = [] # x y = [] # y fig = plt.figure() ax = fig.add_subplot(111) curve,= ax.plot([],[],lw=2) ax.set_xlim(0,5) ax.grid() def tail_f(file): interval = 1.0 while True: where = file.tell() # current file position, an integer (may be a long integer). line = file.readline() if re.search('without errors',line): break if not line: time.sleep(interval) file.seek(where) # seek(offset[, whence]) -> None. Move to new file position. else: yield line def run(): for line in tail_f(open(sys.argv[1])): print line, if re.search('x=',line): liste = line.split('=') x.append(liste[1].strip()) if re.search('y=',line): liste = line.split('=') y.append(liste[1].strip()) curve.set_data(x,y) print x,y # # # run() plt.show() The text file looks like x=0.0 y=0.0 blabla x=1.0 y=1.0 blabla x=2.0 y=4.0 blabla ... Nils ------------------------------------------------------------------------------ Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users