jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.68k stars 4.92k forks source link

Jupyter not displaying SVG plots after reopening notebook #4501

Open Time0o opened 5 years ago

Time0o commented 5 years ago

I have now observed this multiple times yet it is impossible to reproduce because it only happens for some of my notebooks, seemingly arbitrarily: when I produce Matplotlib plots in a Jupyter notebook using %matplotlib inline and plt.show they are displayed correctly, but in some cases shutting down the notebook server, restarting it and then reopening the notebook causes the plots to be replaced by placeholders of the form <Figure size 288x864 with 3 Axes>.

This only seems to happen when I use set_matplotlib_formats('svg') (which I imagine is a common setting) and as mentioned not for every notebook (but for all images in a notebook if it does happen).

I'm using anaconda, jupyter --version is 4.4.0,jupyter notebook --versionis 5.4.0, python --version is 3.6.8 and matplotlib.__version__ is '2.2.3'. This happens for both Chrome and Firefox

This essentially makes Jupyter unuseable for me so I was surprised that I could not find an issue bringing this up. Is this a known issue? Or maybe even intended? Or am I doing something wrong here?

I'll attach the saved output of a cell which should display an SVG image but doesn't (I can't share the whole notebook and as I mentioned I can't seem to produce a minimal example).

``` { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ], "text/plain": [ "

" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "W, b = init_params(d, K)\n", "\n", "plt.hist(W.flatten())\n", "\n", "plt.title(\"Initial Weight Value Distribution\")\n", "\n", "plt.savefig(os.path.join(FIGURE_DIR, 'initial_weights.svg'))" ] }, ```

Ernie1 commented 5 years ago

I also meet this annoying issue. I find no way to reveal them on the notebook, but I find a compromise way to display them on an html page that is File -> Print Preview.

harper357 commented 5 years ago

I think I finally figured this out or at least got it working in my situation. I believe Jupyter is sanitizing the SVG/HTML.

The "fix" is just to select "Trust Notebook" in the File menu. This will cause the page to reload and all the SVGs will now be displayed. I should add that you should only do this for a notebook you know is safe to trust.

vojtech-filipec commented 4 years ago

@harper357 , thank you for this hint - this simplifies my life quite a bit!

The "fix" is just to select "Trust Notebook" in the File menu. This will cause the page to reload and all the SVGs will now be displayed. I should add that you should only do this for a notebook you know is safe to trust.

Hoeze commented 4 years ago

What can I do if there is no such "Trust" option? I created the notebook myself completely but the SVG inline output still disappears upon page reload. That's a quite annoying bug...

harper357 commented 4 years ago

It was removed from the File menu a little while back. It should be in the Console sidebar though.