JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.83k stars 354 forks source link

[FR] savefig("foo.svgz") (gzip-compressed SVG) #4916

Open stevengj opened 6 months ago

stevengj commented 6 months ago

According to the docs, most of the graphical backends support SVG output, but it looks like a lot of them don't support SVGZ (which is simply gzip-compressed SVG).

Matplotlib supports SVGZ and it seems like it would be quite easy to implement similar support for any backend that supports SVG, simply by piping the SVG output through a GZipStream from GZip.jl.

For example, it seems like this works already:

using Plots, GZip
p = plot(...)
gzopen(io -> show(io, "image/svg+xml", p), "bar.svgz", "w") # save as bar.svgz

For a typical plot line plot, e.g. plot(rand(100)) or plot(rand(10^4)), I get compression ratios around 50%.

stevengj commented 6 months ago

This stackoverflow discussion claims that the need for SVGZ is greatly reduced by modern web servers that can compress on the fly, but the responses in the thread dispute this.