python - live updating with matplotlib -


so have phone accelerometry data , make video of motion of phone looked like. used matplotlib create 3d graph of data:

from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot plt import pandas pd import pickle def pickleload(picklefile):     pkl_file = open(picklefile, 'rb')     data = pickle.load(pkl_file)     pkl_file.close()     return data data = pickleload('/users/ryansaxe/desktop/kaggle_parkinsons/accelerometry/lily_dataframe') data = data.reset_index(drop=true) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') xs = data['x.mean'] ys = data['y.mean'] zs = data['z.mean'] ax.scatter(xs, ys, zs) ax.set_xlabel('x label') ax.set_ylabel('y label') ax.set_zlabel('z label') plt.show() 

now time important , factor see 1 point @ time because time factor , lets me watch progression of accelerometry data!

what can make live updating graph?

only thing can think of have loop goes through row row , makes graph row, open many files insane because have millions of rows.

so how can create live updating graph?

here bare-bones example updates fast can:

import pylab plt import numpy np  x = np.linspace(0,2,1000) y = x**2 + np.random.random(x.shape)  plt.ion() graph = plt.plot(x,y)[0]  while true:     y = x**2 + np.random.random(x.shape)     graph.set_ydata(y)     plt.draw() 

the trick not keep creating new graphs continue eat memory, change x,y,z-data on existing plot. use .ion() , .draw() setup canvas updating this.

addendum: highly ranked comment below @kelsey notes that:

you may need plt.pause(0.01) after plt.draw() line refresh show


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -