-1

I have a python program, say, train.py. It can be run in anaconda prompt by typing:

python train.py

In train.py, some part is written for drawing and saving figures:

import matplotlib.pyplot as plt
....... #I omit these codes
plt.savefig(....)
plt.show() #this will produce a figure window 
plt.close()

In implementing the program, some figures are to be generated, which will bring the program to a temporary halt, even though plt.close() present. Then I need to manually close the pop-up figure window due to plt.show() and continue the program. How to avoid this inconvenience.

It is noted that spyder can run the program continuously, with figures displayed in its console.

jingweimo
  • 4,472
  • 8
  • 41
  • 69

1 Answers1

1

plt.show() is meant to be used once in a script to show all figures present. So you can create your figures and show them all at the end

fig1 = plt.figure(1)
# do something with figure 1

fig2 = plt.figure(2)
# do something with figure 2

plt.show() # show both figures
ImportanceOfBeingErnest
  • 289,005
  • 45
  • 571
  • 615