title: Real time dynamic plotting
body: <p>I have a question concerning updating dynamically scatter plots from matplotlib.
  I have the following class in Python</p>
  
  <pre><code>''' PolygonHandler.py - Python source for polygon handling '''
  import numpy as np
  import matplotlib.pyplot as plt
  
  
  class PolygonHandler:
      # Constructor
      def __init__(self):
          self.X = []
          self.Y = []
          self.numberPoints = 0
  
      # Print the polygon
      def draw(self):
          plt.scatter(self.X,self.Y)
          plt.draw()
  
      def update(self):
          for i in range(1,self.numberPoints):
              self.X[i] += np.random.normal()*0.01
              self.Y[i] += np.random.normal()*0.01
  
  
      # append a point
      def add(self,x,y):
          self.numberPoints += 1
          self.X.append(x)
          self.Y.append(y)
  </code></pre>
  
  <p>This class is used in a real time loop that receives information and adds the points to the PolygonHandler class. Now for the purpose of an example, I want to design the following loop</p>
  
  <pre><code>P = PolygonHandler()
  P.add(1,1)
  P.add(2,2)
  P.add(1,2)
  plt.ion()
  plt.show()
  while (True):
      P.draw()
      P.update()
  </code></pre>
  
  <p>How can I tell the interpreter to draw the scatter plots, and once done to remove the former points after updating ? Right now, my plot draws the points and all their previous positions.</p>
  
  <p>Vincent</p>
  
  <p>Thanks a lot for your help</p>
  
  <p>PS : An other problem I have is that the window that is opened by matplotlib freezes and stops answering as soon as I clicked on it (for example to move it to another place on my screen), is there a way to prevent that ?</p>