mi@0: #!/usr/bin/env python mi@0: # encoding: utf-8 mi@0: """ mi@0: animate.py mi@0: mi@0: Created by mi tian on 2015-01-21. mi@0: Copyright (c) 2015 __MyCompanyName__. All rights reserved. mi@0: """ mi@0: mi@0: ''' mi@0: Animate feature from stored data. mi@0: ''' mi@0: import sys, os mi@0: import numpy as np mi@0: import matplotlib.pyplot as plt mi@0: import matplotlib.animation as animation mi@0: mi@0: data = np.genfromtxt('/Users/mitian/Documents/workspace/data/ph.txt',delimiter=',') mi@0: mi@0: fs, stepSize, blockSize = 44100, 2048, 1024 mi@0: # feature_time = 6 mi@0: # feature_window = int(fs / stepSize * feature_time) mi@0: # feature_step = int(0.5 * fs / stepSize * feature_time) mi@0: # nWindow = int((len(data) - feature_window) / feature_step + 1) mi@0: feature_step = 48 mi@0: nWindow = int(len(data) / feature_step) mi@0: mi@0: def animate(i): mi@0: plt.imshow(data[i*feature_step:(i+1)*feature_step, :].T, cmap='hot', origin='lower') mi@0: plt.title('%d-%d(s)' %(3*i, 3*i+6)) mi@0: mi@0: def main(): mi@0: mi@0: print nWindow mi@0: mi@0: fig, ax = plt.subplots() mi@0: ani = animation.FuncAnimation(fig, animate, np.arange(nWindow), interval= 3000) mi@0: plt.show() mi@0: mi@0: if __name__ == '__main__': mi@0: main() mi@0: