title: python matplotlib: plotting in another process
body: <p>EDIT: The ultimate requirement for such a Python program is: Receive data from UART from a external circuitry (which probably is equipped with some sensors), the program will process these data, and draw a dynamically updated curve on the computer screen.</p>
  
  <p>So, I want to plot dynamically, the following test script starts a sub-process, and in that process, it accepts data from parent process through a Queue, and plot data accordingly.</p>
  
  <p>But when the script is run, only an empty figure is shown, I can see the console prints "put:" and "got:" messages, meaning both parent and subprocess are running and communicating, but nothing happens in the GUI figure window. </p>
  
  <p>Furthermore, the GUI window is not responsive and if I click on the window, it will crash.</p>
  
  <p>The system is Windows 10, 64 bit. Python version is 2.7 (32bit)</p>
  
  <p>What's the problem here? thank you!</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import multiprocessing as mp
  import random
  import numpy
  import time
  
  def worker(q):
      plt.ion()
      ln, = plt.plot([], [])
      plt.show()
  
      while True:
          obj = q.get()
          n = obj + 0
          print "sub : got:", n
  
          ln.set_xdata(numpy.append(ln.get_xdata(), n))
          ln.set_ydata(numpy.append(ln.get_ydata(), n))
          plt.draw()
  
  if __name__ == '__main__':
      queue = mp.Queue()
      p = mp.Process(target=worker, args=(queue,))
      p.start()
  
      while True:
          n = random.random() * 5
          print "main: put:", n
          queue.put(n)
          time.sleep(1.0)
  </code></pre>