title: Why can't matplotlib plot in a different thread?
body: <h2>Minimum working example</h2>
  
  <p>I expect the following to show a plot, but i see no plot and the interpreter just hangs (my backend reports itself as <code>TkAgg</code>).</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from threading import Thread
  
  def plot():
      fig, ax = plt.subplots()
      ax.plot([1,2,3], [1,2,3])
      plt.show()
  
  def main():
      thread = Thread(target=plot)
      thread.setDaemon(True)
      thread.start()
      print 'Done'
  </code></pre>
  
  <p>How do I get the plot to display?</p>
  
  <h2>Context</h2>
  
  <p>I am running a simulation with lots iterations and would like to update my plot every 1000 iterations so that I can monitor how my simulation is evolving.</p>
  
  <p>Psuedocode below:</p>
  
  <pre><code>iterations = 100000
  for i in iterations:
      result = simulate(iteration=i)
      if not i % 1000:
          # Update/redraw plot here:
          # Add some lines, add some points, reset axis limits, change some colours
  </code></pre>
  
  <p>Having the plot in the main thread causes the plot GUI to hang/crash presumably because I have other work going on. So the idea was to do the plotting in a separate thread.</p>
  
  <p>I have seen suggestions (e.g. <a href="https://stackoverflow.com/questions/19662906/plotting-with-matplotlib-in-threads">here</a>) to use a process rather than a thread. But then I cannot manipulate the figure or axes to add lines etc while my simulation runs because the figure object is in the remote process.</p>
  
  <h2>Edit</h2>
  
  <p>I'm not convinced this question is a duplicate of <a href="https://stackoverflow.com/questions/31719138/matplotlib-cant-render-multiple-contour-plots-on-django">another one</a> because that question deals with why the <code>pyplot</code> api cannot be used to manipulate <strong>two different plots</strong> that are each on a separate thread. It is because race conditions arising from executing two plots simultaneously prevents <code>pyplot</code> from determining which figure is the <em>current figure</em>.</p>
  
  <p>However, I only have 1 plot and so <code>pyplot</code> only ever has a single and unique <em>current figure</em>.</p>