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()
fig2.show()
the fig1 will only show once, because the plt.close() will destroy the figure object referred by fig1. How can I only close the window without destroy the figure?
So far nothing really works. after each plt.figure(), a new figure_manager is going to be generated. And will be put into a list in plt instance.
>>> print plt.get_fignums()
[1, 2]
however, after plt.close(), the figure_manager of the specific figure will be pop out.
>>> print plt.get_fignums()
[2]
As @John Sharp mentioned plt._backend_mod.new_figure_manager_given_figure(plt.get_fignums()[-1]+1,fig1) will create a new figure_manager for the fig1. However, it has not been added to the plt. So it is impossible to control those figure_manager while plt:
>>> plt._backend_mod.new_figure_manager_given_figure(plt.get_fignums()[-1]+1,fig1)
<matplotlib.backends.backend_tkagg.FigureManagerTkAgg instance at 0x2b0f680>
>>> print plt.get_fignums()
[2]
>>> plt.new_figure_manager(1)
<matplotlib.backends.backend_tkagg.FigureManagerTkAgg instance at 0x2b1e3f8>
>>> plt.get_fignums()
[2]
So it cannot be closed by plt.close(), except directly call figure_manager.destroy()
The suggestion to set current fm directly will be worse:
fm = plt.get_current_fig_manager()
fm.canvas.figure = fig1
fig1.canvas = fm.canvas
at the first glance, this seems work. However, it will directly change the fig2's fm to point to fig1, which will cause lots of trouble.
If there is any way, we can make the pyplot to register manually generated fm, that may work. So far have no luck there.