nbconvert
nbconvert copied to clipboard
nbconvert cannot deal with notebooks containing svg images
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
-
Create a cell with
from matplotlib import pyplot as plt import matplotlib_inline matplotlib_inline.backend_inline.set_matplotlib_formats('svg')
and evaluate it
-
Create a cell with
plt.plot([0,0],[1,1])
and evaluate it
-
Use
jupyter nbconvert
to convert the notebook to html. -
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.
Duplicate of https://github.com/jupyter/nbconvert/issues/1849.
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.
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.
The commit that introduces the SVG issues is: 4b9c5e76
nbconvert 7.2.6
released yesterday still has the same problem (the black figures in the image below are embedded SVGs).

This is still an issue with nbconvert 7.2.7
.
With nbconvert 7.2.9
the output is better but still broken:
The test case by this bug report's OP is still obviously broken as well (the plot is missing the axis labels).
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 can you check if this is still an issue in nbconvert 7.7.x?
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. 👍