title: Stop matplotlib scatter plot to slow down while adding new data
body: <p>i am creating a scatterplot with pyplot but since i am updating this plot with new data, my program is getting slower and slower. Is there a way to update the plot without drawing it new?
  Here is some of my code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  ...
  slicestart = 30 
  sliceend = 50
  #read some data:
  tens_data = ... #3darray 50*321*321
  pert = ...      #3darray 50*321*321
  for slicer in range(slicestart,sliceend):
      tens = tens_data.data[slicer,:,:]
      plt.scatter(tens, pert, s=5, marker='o', color='blue', alpha=0.2)
      plt.grid(True)
      plt.xlabel('tendency')
      plt.ylabel('perturbation')
      plt.draw()
      plt.savefig('sc_test.png')
  </code></pre>
  
  <p>I also tried to do it a little bit different:</p>
  
  <pre><code>...
  sc = plt.scatter([],[])
  
  def update_scatter(sc, new_tens, new_pert):
      sc.set_xdata(np.append(sc.get_xdata(), new_tens))
      sc.set_ydata(np.append(sc.get_ydata(), new_pert))
      plt.xlabel('tendency')
      plt.ylabel('perturbation')
      plt.grid(True)
      plt.draw()
  
  if slicer == slicerstart:
      sc.set_xdata(tens)
      sc.set_ydata(pert)
      plt.xlabel('tendency')
      plt.ylabel('perturbation')
      plt.grid(True)
      plt.draw()
  else:
      update_scatter(sc, tens, pert)
  
  plt.savefig('sc_test.png')
  </code></pre>
  
  <p>but this doesn't work because 'set_xdata' is no attribute for 'scatter'.
  I hope you can help me :)</p>