-1

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 "End of Script" 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.

import time
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot()
plt.show()
time.sleep(2)
plt.close()
print ("End of script")
Menachem
  • 265
  • 1
  • 4
  • 17

1 Answers1

0

Your programs execution will never go past plt.show().
You need to try something like scheduler or thread

Dinesh
  • 1,825
  • 5
  • 31
  • 40