title: asyncio matplotlib show() still freezes program
body: <p>I wish to <strong>run a simulation</strong> while at the <strong>same time output its progress in a plot</strong>. I've been looking through a lot of examples of threading and multiprocessing, but they are all pretty complex. So I thought with Python's new <code>asyncio</code> library this should be easier.</p>
  
  <p>I found an example (<a href="https://stackoverflow.com/questions/37549846/how-to-use-yield-inside-async-function">How to use &#39;yield&#39; inside async function?</a>) and modified it for my cause:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import asyncio
  import numpy as np
  
  
  class DataAnalysis():
      def __init__(self):
          # asyncio so we can plot data and run simulation in parallel
          loop = asyncio.get_event_loop()
          try:
              loop.run_until_complete(self.plot_reward())
          finally:
              loop.run_until_complete(
                  loop.shutdown_asyncgens())  # see: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.shutdown_asyncgens
              loop.close()
  
      async def async_generator(self):
          for i in range(3):
              await asyncio.sleep(.4)
              yield i * i
  
      async def plot_reward(self):
          # Prepare the data
          x = np.linspace(0, 10, 100)
  
          # Plot the data
          plt.plot(x, x, label='linear')
  
          #plt.show()
  
          # add lines to plot
          async for i in self.async_generator():
              print(i)
              # Show the plot
              plt.show()
  
  
  if __name__ == '__main__':
      DataAnalysis()
  </code></pre>
  
  <h2>Question</h2>
  
  <p>I added a simple <code>plt.show()</code> and the program still freezes. I thought with <code>asyncio</code> I could run it in parallel? Obviously my knowledge is still lacking.
  An example that does the following would be really helpful:</p>
  
  <ul>
  <li>Add a line to a plot (of <code>matplotlib</code>) everytime <code>async_generator</code> returns a value.</li>
  </ul>