title: Can you plot live data in matplotlib?
body: <p>I'm reading data from a socket in one thread and would like to plot and update the plot as new data arrives. I coded up a small prototype to simulate things but it doesn't work:</p>
  
  <pre><code>import pylab
  import time
  import threading
  import random
  
  data = []
  
  # This just simulates reading from a socket.
  def data_listener():
      while True:
          time.sleep(1)
          data.append(random.random())
  
  if __name__ == '__main__':
      thread = threading.Thread(target=data_listener)
      thread.daemon = True
      thread.start()
  
      pylab.figure()
  
      while True:
          time.sleep(1)
          pylab.plot(data)
          pylab.show() # This blocks :(
  </code></pre>