title: Animating "growing" line plot in Python/Matplotlib
body: <p>I want to produce a set of frames that can be used to animate a plot of a growing line. In the past, I have always used plt.draw() and set_ydata() to redraw the y-data as it changed over time. This time, I wish to draw a "growing" line, moving across the graph with time. Because of this, set_ydata doesn't work (xdata is changing length). For example,</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  x = np.linspace(0, 10, 100)
  y = np.sin(x)
  
  plt.figure()
  for n in range(len(x)):
      plt.plot(x[:n], y[:n], color='k')
      plt.axis([0, 10, 0, 1])
      plt.savefig('Frame%03d.png' %n)
  </code></pre>
  
  <p>While this works, it becomes very slow as it scales. Is there a faster way to do this?</p>