matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.57k stars 227 forks source link

Still getting "Model not found" error instead of static figure when saving and re-opening the notebook #473

Open nvaytet opened 2 years ago

nvaytet commented 2 years ago

Hi, unfortunately, I am still seeing this error after re-opening the notebook. Screenshot at 2022-06-29 16-31-42

The console log from Chrome: Screenshot at 2022-06-29 16-33-54

Versions:

jupyter_client            7.3.1              pyhd8ed1ab_0    conda-forge
jupyter_core              4.10.0           py39hf3d152e_0    conda-forge
jupyter_server            1.17.0             pyhd8ed1ab_0    conda-forge
jupyterlab                3.4.2              pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
jupyterlab_server         2.14.0             pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        1.1.0              pyhd8ed1ab_0    conda-forge

matplotlib                3.5.2            py39hf3d152e_0    conda-forge
matplotlib-base           3.5.2            py39h700656a_0    conda-forge
matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge

ipydatawidgets            4.3.1.post1        pyhc268e32_0    conda-forge
ipykernel                 6.13.0           py39hef51801_0    conda-forge
ipympl                    0.9.1              pyhd8ed1ab_0    conda-forge
ipython                   8.4.0            py39hf3d152e_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                7.7.0              pyhd8ed1ab_0    conda-forge

Thanks for any help!

Originally posted by @nvaytet in https://github.com/matplotlib/ipympl/issues/343#issuecomment-1170066433

martinRenou commented 2 years ago

Mmh I'm wondering if something has changed in JupyterLab recently that causes this. Would you be able to try to downgrade JupyterLab?

nvaytet commented 2 years ago

Which version should I try?

martinRenou commented 2 years ago

Sorry I didn't mean to close this issue 😕 maybe 3.0?

martinRenou commented 2 years ago

Looks like I'm not the only one closing issues unintentionally https://twitter.com/choldgraf/status/1542169522282860550?s=20&t=7WHeO5lmM8dD62HwB5qHsg

nvaytet commented 2 years ago

I am still getting the "Model not found" error in Jupyterlab=3.0.18

272.3fcd6d7045eecfb56da6.js:1 Failed to fetch ipywidgets through the "jupyter.widget.control" comm channel, fallback to fetching individual model state. Reason: Control comm was closed too early
(anonymous) @ 272.3fcd6d7045eecfb56da6.js:1
(anonymous) @ 272.3fcd6d7045eecfb56da6.js:1
(anonymous) @ 272.3fcd6d7045eecfb56da6.js:1
a @ 272.3fcd6d7045eecfb56da6.js:1
Promise.then (async)
l @ 272.3fcd6d7045eecfb56da6.js:1
s @ 272.3fcd6d7045eecfb56da6.js:1
Promise.then (async)
l @ 272.3fcd6d7045eecfb56da6.js:1
(anonymous) @ 272.3fcd6d7045eecfb56da6.js:1
D @ 272.3fcd6d7045eecfb56da6.js:1
e._loadFromKernel @ 272.3fcd6d7045eecfb56da6.js:1
_loadFromKernel @ 523.66fca84c7924f6f7676d.js:1
await in _loadFromKernel (async)
restoreWidgets @ 523.66fca84c7924f6f7676d.js:1
x @ 523.66fca84c7924f6f7676d.js:1
L @ 523.66fca84c7924f6f7676d.js:1
(anonymous) @ 523.66fca84c7924f6f7676d.js:1
m @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
l @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
e.emit @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
(anonymous) @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
m @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
l @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
e.emit @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
add @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
await in add (async)
add @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
add @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
(anonymous) @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
m @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
l @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
e.emit @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
createNew @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
createWidget @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
_createOrOpenDocument @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
open @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
openOrReveal @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
_handleOpen @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
_evtDblClick @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
handleEvent @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
523.66fca84c7924f6f7676d.js:1 Error: widget model not found
    at x.get_model (523.66fca84c7924f6f7676d.js:1:6292)
    at u.renderModel (523.66fca84c7924f6f7676d.js:1:972)
renderModel @ 523.66fca84c7924f6f7676d.js:1
await in renderModel (async)
_rerender @ 523.66fca84c7924f6f7676d.js:1
m @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
l @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
e.emit @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
restoreWidgets @ 523.66fca84c7924f6f7676d.js:1
await in restoreWidgets (async)
x @ 523.66fca84c7924f6f7676d.js:1
L @ 523.66fca84c7924f6f7676d.js:1
(anonymous) @ 523.66fca84c7924f6f7676d.js:1
m @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
l @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
e.emit @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
(anonymous) @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
m @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
l @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
e.emit @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
add @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
await in add (async)
add @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
add @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
(anonymous) @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
m @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
l @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
e.emit @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
createNew @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
createWidget @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
_createOrOpenDocument @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
open @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
openOrReveal @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
_handleOpen @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
_evtDblClick @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2
handleEvent @ jlab_core.8e0f8627d52a54fc21fe.js?v=8e0f8627d52a54fc21fe:2

Screenshot at 2022-06-30 10-49-52

nvaytet commented 2 years ago

Ah, version 3.0.0 works!

nvaytet commented 2 years ago

Another question: is it at all possible to obtain the same behaviour if the figure is placed inside another (e.g. VBox) widget? Thanks!

Screenshot at 2022-06-30 10-55-47

martinRenou commented 2 years ago

Ah, version 3.0.0 works!

Interesting! So something has changed between 3.0.0 and 3.0.18 that prevents it from displaying the image repr...

Another question: is it at all possible to obtain the same behaviour if the figure is placed inside another (e.g. VBox) widget?

This might be difficult, if the VBox cannot be displayed then we cannot do much about it. Also the VBox embeds the widget representation of the plot, not the image one.

nvaytet commented 2 years ago

What's interesting is:

I am guessing the png repr is correctly being saved by 3.0.0 (I don't know exactly which version broke between 3.0.0 and 3.0.18 yet), and then it can be loaded by later versions.

So this would mean that versions 3.0.18 and higher are failing to save the png rather than load it?

jklymak commented 2 years ago

I can confirm that downgrading (mamba install jupyterlab=3.0.0) also fixes this issue for me.

davidfokkema commented 1 year ago

Can confirm that jupyterlab 3.0.0 does work and that jupyterlab 3.5.2 does not work. Also: the problem seems to be in saving the notebook. A simple notebook saved with 3.0.0 opens with a static image in 3.5.2.

petrovfedor commented 1 year ago

I can confirm @davidfokkema. That 3.0.0 works and 3.5.2 not. Moreover in our case we use widgets with asynchronous calls. And this problem leads to widgets disappearing from the notebook approximately after one minute idle.

petrovfedor commented 1 year ago

Just tested this with 3.5.0 and it works.

jklymak commented 1 year ago

I get "Error displaying widget: model not found" with the following env (and jupyterlab 3.6.1):

$ mamba list jupyterlab
# packages in environment at /Users/jklymak/mambaforge/envs/LP22a:
#
# Name                    Version                   Build  Channel
jupyterlab                3.5.0              pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
jupyterlab_server         2.19.0             pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        3.0.5              pyhd8ed1ab_0    conda-forge
(LP22a)
# jklymak @ quadra in ~/Dropbox/LP22a [16:05:37]
$ mamba list ipympl
# packages in environment at /Users/jklymak/mambaforge/envs/LP22a:
#
# Name                    Version                   Build  Channel
ipympl                    0.9.3              pyhd8ed1ab_0    conda-forge
(LP22a)

jupyterlab 3.0.0 works though.

lrlunin commented 1 year ago

Not working in the jupyterlab 3.6.4 either.

vincefn commented 4 months ago

This is a bit old, but I just ran into this with a fresh installation of ipympl (0.9.4) & jupyter-lab (4.2.1).

However there is now a jupyter-lab menu Settings->Save Widget State Automatically which resolved this. Now the plots (the embedded png) are correctly displayed after re-opening a shutdown'd notebook. And it's also correctly displayed using nbsphinx as well.