python - Matplotlib animation panning the x axis -


i building pyqt4 gui plots scatter plot of points file. now, these points paired x,y in .txt file. basically, x data time in milliseconds , y event happening @ particular time. want create animated matplotlib scatter plot pans time axis 0 time t, lets 1000 ms while time(x) axis pans in 100 ms frames or sections. plot appears moving 0 time t while plotting these points.

the data sample shown below:

105.40000000000001  330.0 105.40000000000001  344.0 105.5   259.0 105.5   262.0 ......... ..... 

and on..

i trying use funcanimation of matplotlib takes update method try add more data scatter plot. how pan time axis in 100 ms steps.

i tried using data generator yields next data point every time update method called, time axis kind of slows down while there more points.

here have tried far.

ani = animation.funcanimation(self.figure,self._upd_plot,self.data_gen,blit=false, interval=10, repeat=false) def data_gen(self):     d in self.data:         yield d  def init_ani(self):     self.g = self.data_gen()  def _upd_plot(self,d):     d = next(g)     self.time.append(d[0])     self.neu.append(d[1])     self.scat.set_xdata(self.time)     self.scat.set_ydata(self.neu)     self.canvas.draw() 

where problem? appreciated. pardon bad english

it might idea work on points plotted, instead of appending them list, if latter slows things down.

here example of how imagine such panning animation plot , seems work fine.

import matplotlib.pyplot plt import numpy np import matplotlib.animation animation  class some():     def __init__(self):         self.fig = plt.figure()         self.ax = self.fig.add_subplot(111)         self.line,  = self.ax.plot([],[], color="red", linestyle="-")         self.scat, = self.ax.plot([],[], color="orange", marker="s", linestyle="")          self.data = np.random.rand(1000)         self.times = np.arange(1000)          self.stepsize = 10         self.showntimes = np.arange(self.stepsize)         self.ax.set_ylim([0,1])         self.ax.set_xlim([self.showntimes[0],self.showntimes[-1]])          self.ani = animation.funcanimation(self.fig, self._upd_plot, blit=false, interval=60, repeat=false)         plt.show()      def _upd_plot(self,i):         print         if < len(self.data)-self.stepsize:             self.scat.set_data(self.showntimes, self.data[i:i+self.stepsize])             self.line.set_data(self.showntimes, self.data[i:i+self.stepsize].mean()*np.ones(len(self.showntimes)) )             self.ax.set_xticklabels(self.times[i:i+self.stepsize])         else:             self.ani.event_source.stop()  if __name__ == '__main__':     s = some() 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -