# Save plot as a JPEG file

**URL:** <https://discourse.julialang.org/t/save-plot-as-a-jpeg-file/112684>\
**Category:** Graphs\
**Tags:** graphics\
**Created:** [April 8, 2024, 3:39pm UTC](https://discourse.julialang.org/t/save-plot-as-a-jpeg-file/112684 "2024-04-08T15:39:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eweiss](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@eweiss](https://discourse.julialang.org/u/eweiss)\
**Post date:** [April 8, 2024, 3:39pm UTC](https://discourse.julialang.org/t/save-plot-as-a-jpeg-file/112684/1 "2024-04-08T15:39:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 8, 2024, 3:57pm UTC](https://discourse.julialang.org/t/save-plot-as-a-jpeg-file/112684/2 "2024-04-08T15:57:02Z")

</div>

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](https://en.wikipedia.org/wiki/SVG#Compression), 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](https://github.com/JuliaPlots/Plots.jl/issues/4916)) 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:

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

```
