How to suppress svg output by IJulia in Jupyter notebooks

40 Views Asked by At

I use julia and Plots.jl in a jupyter notebook to create large scatter plots with up to 10^7 items. By default I get svg output, which makes Safari really sluggish. It also causes huge bloat in the .ipynb notebook file which stores the entire svg inline.

I specified format = :png and fmt = :png and get rasterised output in the browser. This helps to speed up things a lot. In the .ipynb file, however, I now see both the svg and the base64 encoded png, which makes the bloat even worse.

Converting my notebooks to pdf using nbconvert grinds to a halt in both cases.

I made some effort trying to using other julia plotting backends than the default one. This has mostly failed me due to installation woes (bad/outdated descriptions, not applicable to Mac, installations failing).

Google turns up a lot of results for the converse, i.e. people get rasterised output and want svg for higher quality. I specifically want rasterised output because this is much smaller and faster than the vectorised one in my use case.

Any pointers would be welcome.

1

There are 1 best solutions below

3
Przemyslaw Szufel On BEST ANSWER

Save picture to a file:

f = tempname()*".png";
p = Plots.scatter(rand(10^7), rand(10^7),markersize=1);
savefig(p, f);

Than display the file in the notebook:

using FileIO, ImageIO, ImageShow
FileIO.load(f)

The notebook size in mine case is 1MB - image included.

enter image description here

EDIT

After checking once again, you can provide mime type to display function to get the desired behavior:

display("image/png", p)

This seems to generate just png, not the slow svg.