python - Passing arguments in animation.FuncAnimation() -


how pass arguments animation() function? , tried dint worked. prototype of animation.funcanimation()

class matplotlib.animation.funcanimation(fig, func, frames=none, init_func=none, fargs=none, save_count=none, **kwargs) bases: matplotlib.animation.timedanimation

i have pasted code below , changes have make?

import matplotlib.pyplot plt import matplotlib.animation animation  def animate(i,argu):     print argu      graph_data = open('example.txt','r').read()     lines = graph_data.split('\n')     xs = []     ys = []     line in lines:         if len(line) > 1:             x, y = line.split(',')             xs.append(x)             ys.append(y)         ax1.clear()         ax1.plot(xs, ys)         plt.grid()  ani = animation.funcanimation(fig,animate,fargs = 5,interval = 100) plt.show() 

check simple example:

# -*- coding: utf-8 -*- import matplotlib.pyplot plt  import matplotlib.animation animation import numpy np  data = np.loadtxt("example.txt", delimiter=",") x = data[:,0] y = data[:,1]  fig = plt.figure() ax = fig.add_subplot(111) line, = ax.plot([],[], '-') line2, = ax.plot([],[],'--') ax.set_xlim(np.min(x), np.max(x)) ax.set_ylim(np.min(y), np.max(y))  def animate(i,factor):     line.set_xdata(x[:i])     line.set_ydata(y[:i])     line2.set_xdata(x[:i])     line2.set_ydata(factor*y[:i])     return line,line2  k = 0.75 # factor  ani = animation.funcanimation(fig, animate, frames=len(x), fargs=(k,),                               interval=100, blit=true) plt.show() 

first, data handling recommended use numpy, simplest read , write data.

isn't necessary use "plot" function in each animation step, instead use set_xdata , set_ydata methods update data.

also reviews examples of matplotlib documentation: http://matplotlib.org/1.4.1/examples/animation/.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -