title: Dynamically update plot in iPython notebook
body: <p>As referred in <a href="https://stackoverflow.com/questions/21360361/how-to-dynamically-update-a-plot-in-a-loop-in-ipython-notebook-within-one-cell">this question</a>, I am trying to update a plot dynamically in an iPython notebook (in one cell).
  The difference is that I don't want to plot new lines, but that my x_data and y_data are growing at each iteration of some loop.</p>
  
  <p>What I'd like to do is:</p>
  
  <pre><code>import numpy as np
  import time
  plt.axis([0, 10, 0, 100]) # supoose I know what the limits are going to be
  plt.ion()
  plt.show()
  x = []
  y = []
  for i in range(10):
       x = np.append(x, i)
       y = np.append(y, i**2)
       # update the plot so that it shows y as a function of x
       time.sleep(0.5) 
  </code></pre>
  
  <p>but I want the plot to have a legend, and if I do</p>
  
  <pre><code>from IPython import display
  import time
  import numpy as np
  plt.axis([0, 10, 0, 100]) # supoose I know what the limits are going to be
  plt.ion()
  plt.show()
  x = []
  y = []
  for i in range(10):
      x = np.append(x, i)
      y = np.append(y, i**2)
      plt.plot(x, y, label="test")
      display.clear_output(wait=True)
      display.display(plt.gcf())
      time.sleep(0.3)
  plt.legend()
  </code></pre>
  
  <p>I end up with a legend which contains 10 items. If I put the <code>plt.legend()</code> inside the loop, the legend grows at each iteration... Any solution? </p>