if I create a figure then do plt.close() :
from matplotlib import pyplot as plt
fig1 = plt.figure()
fig2 = plt.figure()
fig1.show()
plt.close()
fig1.show()
fig
Since the Figure is still referenced by the name fig1 it is not destroyed. You just need to create a new figure manager for the figure. One way to do this is to get a new figure manager by generating a new blank figure and manually set the canvas figure to be fig1:
plt.figure()
fm = plt.get_current_fig_manager()
fm.canvas.figure = fig1
fig1.canvas = fm.canvas
Once you've done this you can show and then close the figure with:
fig1.show()
plt.close()
Alternatively, if you were showing two figures at once and only wanted to close a particular one, instead of using plt.close()
you can call the fm.destroy()
method to close the window showing only the particular figure referenced by that frame manager.