title: animation plot in matplotlib with double for loop
body: <p>I would like to create an animation with matplotlib in python. As the animated data is function of two parameter (time, number of bodies) I got an idea to use 2 for loops. The code is below:</p>
  
  <pre><code>import time
  import matplotlib as mpl
  from matplotlib import pyplot as plt
  from matplotlib import pylab as plb
  
  #   set up figure for plotting:
  fig = plt.figure()
  ax = fig.add_subplot(111)
  
  #    plot limits
  ax.set_xlim(-(max(q0) + bodies[-1].L), +(max(q0) + bodies[-1].L))
  ax.set_ylim(-(max(q0) + bodies[-1].L), +(max(q0) + bodies[-1].L))
  
  #    colors
  colors = ['b', 'g', 'c']
  
  
  for i_t in range(0, np.shape(t)[1]):    #t is an one column matrix
      for i in range(0, N):
          ax.plot(x_matrix[i_t, i], y_matrix[i_t, i], 's', color=colors[i])
      plt.draw()
  plt.show()
  </code></pre>
  
  <p>The problem is that the code generates me one plot but with all animated points. I would like to have the animation ploted for one time value (counter i_t) and all bodies (counter i) in one window as a movie so the previous plot is erased at the next time step.</p>
  
  <p>I have changed the code you suggested to:</p>
  
  <pre><code>for i_t in range(0, np.shape(t)[1]):
      for i in range(0, N):
          ax.clear()
          ax.plot(x_matrix[i_t, i], y_matrix[i_t, i], 's', color=colors[i])
          plt.pause(0.001)
  plt.draw()
  </code></pre>
  
  <p>But then I get an error:</p>
  
  <blockquote>
    <p>C:\Python27\lib\site-packages\matplotlib\backend_bases.py:2292:
    MatplotlibDeprecationWarning: Using default event loop until function
    specific to this GUI is implemented   warnings.warn(str,
    mplDeprecation)</p>
  </blockquote>
  
  <p>That isn't so frightening but when running the code the points that would have to be plotted together (counter i) are plotted apart so it looks like blinkig dots (if you know what I mean).</p>
  
  <p>Any suggestions. I think I am close to the solution, but still need the finishig touch for the code to be working. I hope this can be done the way I imagined so I would not have to solve the problem with different approach.</p>