if I create a shape, then plt.close ():
from matplotlib import pyplot as plt fig1 = plt.figure() fig2 = plt.figure() fig1.show() plt.close() fig1.show() fig2.show()
fig1 will only be displayed once, since plt.close () will destroy the shape object shown in fig. 1. How can I close the window without destroying the figure?
So far, nothing really works. after each plt.figure () a new figure_manager will be created. And will be listed in the plt instance.
>>> print plt.get_fignums() [1, 2]
however, after plt.close (), the figure_mander of a particular drawing will appear.
>>> 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 fig_manager for fig1. However, it was not added to plt. Thus, it is not possible to control these manipulator figures 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]
Therefore, it cannot be closed by plt.close (), except for a direct call to figure_manager.destroy ()
The suggestion to set the current fm directly will be worse:
fm = plt.get_current_fig_manager() fm.canvas.figure = fig1 fig1.canvas = fm.canvas
at first glance, it seems to work. However, it will directly modify fig2 fm to point to fig1, which will cause a lot of problems.
If there is any way, we can force pyplot to register manually created fm that may work. So far theyβre out of luck.