You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_tkinter.TclError: can't invoke "wm" command: application has been destroyed #10287
plt.show()
fig.savefig('./result.png',bbox_inches='tight') # save the figure to file
plt.close(fig) # close the figure
OS: Ubuntu 16.04,
The error:
fig.savefig('./result.png',bbox_inches='tight') # save the figure to file
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1834, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2188, in print_figure
self.figure.dpi = dpi
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 436, in _set_dpi
self.set_size_inches(w, h, forward=forward)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 745, in set_size_inches
manager.resize(int(canvasw), int(canvash))
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 540, in resize
self.canvas._tkcanvas.master.geometry("%dx%d" % (width, height))
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1667, in wm_geometry
return self.tk.call('wm', 'geometry', self._w, newGeometry)
_tkinter.TclError: can't invoke "wm" command: application has been destroyed
Interestingly this is really a problem of the Tk backend. Using the Qt backend, it is possible to save the figure, even if the window does not exist anymore. The following works:
Activity
ImportanceOfBeingErnest commentedon Jan 22, 2018
Apparently the tk backend needs the figure window to be able to save the figure inside of it. Hence using the tk backend, the following fails.
The usual way to circumvent this problem is to first save the figure and than show it. The following works as expected:
Interestingly this is really a problem of the Tk backend. Using the Qt backend, it is possible to save the figure, even if the window does not exist anymore. The following works:
So the issue here, if any, is probably rather: Is it really necessary for the Tk backend to have a window present in order to save a figure?
anntzer commentedon Jan 22, 2018
I think this is an issue similar to #8736; we should not be using the same figure manager to save the plot but just instantiate a new one.
anntzer commentedon Jan 28, 2018
Closed by #10292.
use agg backend when creating animate