title: How to dynamically update a plot in a loop in IPython notebook (within one cell)
body: <p>Environment: Python 2.7, <a href="https://en.wikipedia.org/wiki/Matplotlib" rel="noreferrer">Matplotlib</a> 1.3, IPython notebook 1.1, Linux, and Chrome. The code is in one single input cell, using <code>--pylab=inline</code>.</p>
  <p>I want to use IPython notebook and Pandas to consume a stream and dynamically update a plot every five seconds.</p>
  <p>When I just use a print statement to print the data in text format, it works perfectly fine: the output cell just keeps printing data and adding new rows. But when I try to plot the data (and then update it in a loop), the plot never shows up in the output cell. But if I remove the loop, and just plot it once, it works fine.</p>
  <p>Then I did some simple test:</p>
  <pre><code>i = pd.date_range('2013-1-1',periods=100,freq='s')
  while True:
      plot(pd.Series(data=np.random.randn(100), index=i))
      #pd.Series(data=np.random.randn(100), index=i).plot() also tried this one
      time.sleep(5)
  </code></pre>
  <p>The output will not show anything until I manually interrupt the process (<kbd>Ctrl</kbd> + <kbd>M</kbd> + <kbd>I</kbd>). And after I interrupt it, the plot shows correctly as multiple overlapped lines. But what I really want is a plot that shows up and gets updated every five seconds (or whenever the <code>plot()</code> function gets called, just like what print statement outputs I mentioned above, which works well). Only showing the final chart after the cell is completely done is <em>not</em> what I want.</p>
  <p>I even tried to explicitly add the draw() function after each <code>plot()</code>, etc. None of them works. How can I dynamically update a plot by a <em>for</em>/<em>while</em> loop within one cell in IPython notebook?</p>