title: How to make change of variables in animation.Funcanimation function in Python?
body: <p>I am actually working on a Python Project where I need to animate variations over time of a concentration, to do so I need the values of my concentration at time t-1 to calculate the concentration at time t.</p>
  
  <p>I would like the "animate" function to use the new values of n0 and n1 when being called. Presently it only uses the same values of n0 and n1 as I declared them in my initial conditions and do not take into account the changes it makes to n0 and n1 during the first plot.</p>
  
  <p>Here is a sample of my code (K, L and M are constant floats):</p>
  
  <pre><code># Initial conditions
  
  n0 = f(X)
  n1 = n0.copy()
  
  n1[1:-1] = K * (n0[0:-2] - 2 * n0[1:-1] + n0[2:]) - L * (n0[2:] - n0[:-2]) + M * n0[1:-1]
  n0 = n1.copy()
  
  # Animation
  
  
  fig = plt.figure()
  ax = plt.axes(xlim=(-0.5, 1.3), ylim=(min(f(X)), max(f(X))), xlabel="x", ylabel="n", title="n en fonction de x")
  line, = ax.plot([], [], lw=2)
  time_text = ax.text(0.02, 0.95, '', transform=ax.transAxes)
  
  def init():
      time_text.set_text('')
      line.set_data([],[])
      return line, time_text
  
  def animate(i,n0,n1):
      n1[1:-1] = K * (n0[0:-2] - 2 * n0[1:-1] + n0[2:]) - L * (n0[2:] - n0[:-2]) + M * n0[1:-1]
      n0 = n1.copy()
      t = i * dt
      time_text.set_text('time = %f ms' % (t * 1000))
      y = n1
      line.set_data(X, y)
      return line, time_text
  
  
  ani = animation.FuncAnimation(fig, animate, init_func=init, frames=nt, blit=True, interval=1, repeat=False, fargs=(n0, n1))
  
  plt.show()
  </code></pre>
  
  <p>Hope you can help me because I am a new user of animation.Funcanimation and I do not understand everything about it.</p>