title: Matplotlib stops animating after first frame
body: <p>I'm trying to animate two subplots, each with multiple lines. I am using <a href="http://matplotlib.org/">Matplotlib</a>, and I am using the <a href="http://matplotlib.org/api/animation_api.html#matplotlib.animation.FuncAnimation"><code>FuncAnimation</code></a>, which is used by many of the <a href="http://matplotlib.org/examples/animation/index.html">animation examples</a>.</p>
  
  <h3>Using animation:</h3>
  
  <p>If I try to animate it, I only get the result of the first frame:
  <img src="https://i.stack.imgur.com/F1Ktb.png" alt="with animation"></p>
  
  <h3>Without using animation:</h3>
  
  <p>If I manually call my <code>update_lines</code> function, it works fine.
  <img src="https://i.stack.imgur.com/fazAV.png" alt="without animation"></p>
  
  <h3>Code:</h3>
  
  <p>Below is the full code (uncommenting the 3 indicated lines in <code>main()</code> works, but I would like to see it update in real-time, hence trying to use the animation).</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from matplotlib.animation import FuncAnimation
  
  
  def make_subplots():
      def setup_axes(axes):
          for ax in axes:
              ax.set_xbound(0, 100)  # bound will change as needed.
              ax.set_ylim(0, 1)  # limit won't change automatically.
  
      def make_lines(axes):
          labels = ('a', 'b', 'c')
          lines = []
          for ax in axes:
              ax_lines = []
              for label in labels:
                  x, y = [0], [0]
                  line, = ax.plot(x, y, label=label)  # comma for unpacking.
                  ax_lines.append((line, x, y))
              lines.append(ax_lines)
          return lines
  
      fig, axes = plt.subplots(2, 1, sharex=True, sharey=True)
      lines = make_lines(axes)
      setup_axes(axes)
      return fig, axes, lines
  
  
  def make_data():
      for i in xrange(100):
          print 'make_data():', i
          data = dict()
          for label in ('a', 'b', 'c'):
              from random import random
              data[label] = random()
          yield (i + 1, data)
  
  
  def update_lines(data, lines):
      print 'update_lines():', data, lines
      updated_lines = []
      for ax_lines in lines:
          for line, x, y in ax_lines:
              label = line.get_label()
              x.append(data[0])
              y.append(data[1][label])
              line.set_data(x, y)
              updated_lines.append(line)
  
  
  def main():
      fig, axes, lines = make_subplots()
  
      # Uncomment these 3 lines, and it works!
      # new_data = make_data()
      # for data in new_data:
      #     update_lines(data, lines)
  
      FuncAnimation(fig=fig,
                    func=update_lines,
                    frames=make_data,
                    fargs=(lines,),
                    interval=10,
                    blit=False)
  
      plt.show()
  
  
  if __name__ == '__main__':
      main()
  </code></pre>