Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Image: ubuntu2204-dev
SVG or PNG plots in CoCalc Notebooks
Type | pros | cons |
---|---|---|
SVG | higher resolution | size and rendering time proportional to number of elements |
PNG | screen resolution, could be 2x oversampled for high res monitors | constant size, proportional to number of pixels and overall complexity, constant rendering time |
NOTE: This is for the Python 3 kernel. It does not work for the SageMath kernels. See 35972.
Default: PNG plots with 2x oversampling ("retina")
This is configured by default on CoCalc via
This plot has a size of about 142kB and works well on modern high resolution screens.
... or as just a simpler PNG without oversampling, with a size of just about 60kB. If you have a high resolution screen, you'll notice fuzziness around sharp edges and characters.
SVG
Configure the backend for drawing inline plots to use SVG
The plot below has a size of only 27kB.
10.000 points?
Here, SVG grows larger than PNG.
Warning If you up this to 100.000 and plot SVG, your browser might eat up a lot of your computers resources, since it has to draw so much!
This PNG plot has about 110kB.
While this SVG is more than 1MB (compressed it is less, though), and it takes a bit to even render it in your browser. With more elements to draw, the local performance of showing this SVG will suffer even more, while the performance of rendering a PNG is essentially constant.
Summary:
If your plots are of low complexity with only a moderate number of elements, there are benefits to redering as SVG (or PDF). They can be blown up in size without pixelation, used in vector graphic drawing tools like Inkscape, etc.
Across all possible situations though, a high resolution PNG will give you a good looking image with a predictable performance. You loose the ability to scale it up arbitrarily, though. What you can do is changing the size of the plotted image.
Other backends?
Most of them are for desktop computers, which do not apply here on CoCalc – an online web-appliction.
Still, let's try PDF. This will not show up, but create a link. You might want to use that variant, if you include a plot in a larger PDF document, e.g. LaTeX
Invalid PDF output
Bonus: changing figure size
and you can also adjust the resolution (dpi)