holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.68k stars 402 forks source link

_tkinter.TclError: can't invoke "wm" command: application has been destroyed #1910

Closed euskov closed 5 years ago

euskov commented 6 years ago

The following code sample raises

_tkinter.TclError: can't invoke "wm" command: application has been destroyed

for matplotlib >= 2.0:

import holoviews as hv
from geoviews import feature as gf

img = gf.land
renderer = hv.renderer('matplotlib').instance(fig='png')
renderer.save(img, 'wtf')

The exception is raised by the following line in site-packages/matplotlib/figure.py:

self.set_size_inches(*self.get_size_inches())

which calls Tk geometry command on closed figure with destroyed Tk handle (figure is closed at the end of _finalize_axis(self, key) method in site-packages/holoviews/plotting/mpl/plot.py).

Furthermore, the above code sample works fine for matplotlib 1.5. It seems that _set_dpi method changed slightly in 2.0, and one of the changes is Tk geometry call.

philippjfr commented 6 years ago

Thanks for reporting this. Does it still work with a different renderer, e.g. GTK or Qt?

euskov commented 6 years ago

How can I set these renderers? The only renderers I can find from the code are matplotlib, bokeh and plotpy:

    _backends = {'matplotlib': 'mpl',
                 'bokeh': 'bokeh',
                 'plotly': 'plotly'}

I guess that other renderers should work because all code which is related to this problem is located inside holoviews/plotting/mpl package.

philippjfr commented 6 years ago

Sorry should have been clearer and I actually meant matplotlib backends in particular, see here for a primer on that. That said this is definitely a bug and should be fixed, I just wanted to see whether it affects all GUI backends or just Tk.

euskov commented 6 years ago

For some reason it was quite a challenge to build these backends from sources. I only succeeded with building Qt4Agg, and this backend successfully renders the image without errors.

jlstevens commented 6 years ago

Glad it is now working!

@philippjfr Do you think there is anything we can do about this or should we just close the issue under the assumption that this is an occasionally issue with the Tk backend which isn't usually the default?

philippjfr commented 6 years ago

Not sure, let's leave it open until someone has had time to investigate.

philippjfr commented 6 years ago

Have not been able to reproduce.

philippjfr commented 6 years ago

Reopening, someone reported the same issue here: https://github.com/pydata/xarray/issues/2030

philippjfr commented 5 years ago

The solution here is simply to switch to agg, so I'll close again.