title: python matplotlib cannot close the plot programmatically
body: <p>I am using python 3.9 on a windows 10 with IDLE. I have a complex program and I isolated the problem to the simple example below. The script succssfuly displays the figure however the figure window does not close after 2 seconds. It stays open forever until I close it manualy by clicking the X on the upper right corner of the plot window. After I close the window, the script waits for 2 seconds and prints the &quot;End of Script&quot; text as expected. For whatever reason the plt.close() does not close the plot window when the script is running. I cannot find anything wrong with the code nor could I find an answer to similar questions that works. Any help is appreciated.</p>
  <pre><code>import time
  import matplotlib.pyplot as plt
  fig = plt.figure()
  ax = fig.add_subplot()
  plt.show()
  time.sleep(2)
  plt.close()
  print (&quot;End of script&quot;)
  </code></pre>