Is there any way to save a plot (from Plots but I’m open to something else) as a jpeg? I’m creating several hundred simple line graphs as pngs, but I’d like to speed loading on the web by jusing a jpeg.None of the Julia packages seem to do this.
With the PythonPlot backend (Matplotlib) you should be able to do savefig("foo.jpg")
to save as JPEG. (Or using PyPlot or PythonPlot directly, of course.) You can also save as PNG and then batch-convert to JPEG with some tool, e.g. ImageMagick.
That being said, for simple line graphs it’s probably more efficient to save as PDF or gzip-compressed SVG, or even uncompressed SVG. e.g. if I do plot(rand(100))
and do savefig
in various formats, I get 34kB for JPEG (with the default compression settings), 54kB for PNG, 14kB for SVG (uncompressed), 7kB for PDF, and 4kB for .svgz
(gzip-compressed).
(Moreover, for line graphs PDF and SVG are effectively “infinite resolution”, i.e. you can zoom them arbitrarily.)
PS. Plots does not currently support .svgz
for most backends ([FR] savefig("foo.svgz") (gzip-compressed SVG) · Issue #4916 · JuliaPlots/Plots.jl · GitHub) though it should work for Matplotlib / PythonPlot / PyPlot. But you can always gzip
the .svg
files after they are created. Or you can do it directly via the GZip.jl package:
using Plots, GZip
p = plot(...)
gzopen(io -> show(io, "image/svg+xml", p), "bar.svgz", "w") # save as bar.svgz