1 import numpy as np 2 import matplotlib.pyplot as plt 3 import collections 4 5 HZ = 500; 6 T_SPAN = 10; 7 T_avg = 10; 8 plt.ion() # This allows for interactive plots, i.e. plots that do not block execution of the script 9 10 wave = collections.deque(np.zeros(HZ*T_SPAN), maxlen=HZ * T_SPAN) 11 buff = collections.deque(np.zeros(HZ*T_SPAN), maxlen=HZ * T_avg) 12 13 while True: 14 for i in xrange(HZ): 15 buff.append(float(raw_input())) 16 wave.append(sum(buff)/float(len(buff))) 17 plt.clf() 18 plt.plot(range(HZ * T_SPAN), list(wave)) 19 plt.axis([-1, T_SPAN*HZ, 0.0, 0.4]) 20 plt.pause(0.01) 21