title: Plotting a continuous stream of data with MatPlotLib
body: <p>I want to use MatPlotLib to plot a graph, where the plot changes over time. At every time step, an additional data point will be added to the plot. However, there should only be one graph displayed, whose appearance evolves over time.</p>
  
  <p>In my test example, the plot is a simple linear plot (y = x). Here is what I have tried:</p>
  
  <pre><code>for i in range(100):
      x = range(i)
      y = range(i)
      plt.plot(x, y)
      plt.ion()
      plt.show()
      time.sleep(1)
  </code></pre>
  
  <p>However, what happens here is that multiple windows are created, so that by the end of the loop I have 100 windows. Also, I have noticed that for the most recent window, it is just a white window, and the plot only appears on the next step.</p>
  
  <p>So, my two questions are:</p>
  
  <p>1) How can I change my code so that only a single window is displayed, whose contents changes over time?</p>
  
  <p>2) How can I change my code so that for the most recent timestep, the plot is actually displayed on the window, rather than it only displaying a white window?</p>
  
  <p>Thanks!</p>