nbconvert icon indicating copy to clipboard operation
nbconvert copied to clipboard

nbconvert cannot deal with notebooks containing svg images

Open callegar opened this issue 2 years ago • 10 comments

Description

If you use something like matplotlib_inline.backend_inline.set_matplotlib_formats('svg') then matplotlib produces images in the svg format. In many situations this is a good thing with respect to the image quality.

However, if you have this kind of images in the notebook, then nbconvert cannot deal with them.

Reproduce

  1. Create a cell with

    from matplotlib import pyplot as plt
    import matplotlib_inline
    matplotlib_inline.backend_inline.set_matplotlib_formats('svg')
    

    and evaluate it

  2. Create a cell with

    plt.plot([0,0],[1,1])
    

    and evaluate it

  3. Use jupyter nbconvert to convert the notebook to html.

  4. Open the html with a browser

Expected behavior

You should see a plot after point 2. above and then that should be also in the webpage seen at point 4. However at 4. you get a web page with no plot.

callegar avatar Sep 09 '22 10:09 callegar

Duplicate of https://github.com/jupyter/nbconvert/issues/1849.

goyodiaz avatar Sep 12 '22 09:09 goyodiaz

I'm also seeing this problem where SVG images are displayed as code instead of an image. The most recent version that works for me is nbconvert 6.5.2.

Later 6.5.x versions just display a blank area where the SVG should be, and 7.x versions up to 7.2.2 display the SVG as code.

nbconvert 7.2.3 (the latest version as I write this) works.

carlosefr avatar Oct 28 '22 16:10 carlosefr

I've done more tests and I now see that nbconvert 7.2.3 is still broken (e.g. SVG output from Plotly is rendered as a black rectangle) and the version that seems to work reliably is actuall nbconvert 6.5.0 (version 6.5.1 shows blank SVGs).

I'm testing with Jupyter Lab 3.4.8.

carlosefr avatar Nov 02 '22 14:11 carlosefr

The commit that introduces the SVG issues is: 4b9c5e76

carlosefr avatar Nov 02 '22 15:11 carlosefr

nbconvert 7.2.6 released yesterday still has the same problem (the black figures in the image below are embedded SVGs).

image

carlosefr avatar Dec 06 '22 10:12 carlosefr

This is still an issue with nbconvert 7.2.7.

carlosefr avatar Dec 21 '22 12:12 carlosefr

With nbconvert 7.2.9 the output is better but still broken: image

The test case by this bug report's OP is still obviously broken as well (the plot is missing the axis labels). image

carlosefr avatar Feb 27 '23 12:02 carlosefr

Is there a plan to fix this? I just tested nbconvert 7.4.0 and this is still an issue. With all the graphing toolkits using SVG, this is a relevant bug...

carlosefr avatar Jun 07 '23 15:06 carlosefr

@carlosefr can you check if this is still an issue in nbconvert 7.7.x?

jstorrs avatar Jul 25 '23 13:07 jstorrs

With nbconvert 7.7.2 I no longer see issues with the test cases that I have (above). I'll keep using this version and wil report if I find any issues, but it looks good. 👍

carlosefr avatar Jul 25 '23 14:07 carlosefr