MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.38k stars 302 forks source link

CairoMakie errors with jpg output #869

Open ericphanson opened 3 years ago

ericphanson commented 3 years ago
using CairoMakie

fig1 = plot(rand(1:100, 100))
fig2 = plot!(rand(100))
CairoMakie.save("fig1.png", fig1) # works
CairoMakie.save("fig2.png", fig2) # errors, though maybe that's expected? confusing error message though
CairoMakie.save("fig1.jpg", fig1) # errors, seems like a bug

with

pkg> st -m CairoMakie AbstractPlotting FileIO ImageMagick
Status `~/car-t/ArtifactDetective.jl/scripts/Manifest.toml`
  [537997a7] AbstractPlotting v0.15.24
  [13f3f980] CairoMakie v0.3.18 `https://github.com/JuliaPlots/CairoMakie.jl.git#master`
  [5789e2e9] FileIO v1.6.2
  [6218d12a] ImageMagick v1.1.7
jkrumbiegel commented 3 years ago

We don't have jpg output anymore. That's just because Cairo has only png output and you can of course convert to jpg, but that can only lower your quality. So it didn't really seem sensible to include it. Then we could as well offer every file format that ImageMagick can convert to, which is pretty confusing I think.

The second thing errors because the mutating plotting functions all return plot objects, and you can't save those. The first one returns FigureAxisPlot which together with Scene and Figure works for saving.

ericphanson commented 3 years ago

Ok, makes sense. I wonder if a more clear error can be thrown for CairoMakie.save("fig2.png", fig2)? It dumps a bunch of FileIO stuff currently.

jkrumbiegel commented 3 years ago

you mean overload AbstractPlot for saving with an error-message like "don't do this, save the scene/ figure" because that's something people could do often?

ericphanson commented 3 years ago

Yeah, I think that would help. It was confusing to me especially because I was getting that same message due to bugs (i.e. when saving a scene/figure) until I updated and switched to CairoMakie master. So IMO a custom error message would help make it clear how you're supposed to use these things and when it's an unexpected error vs an expected one.

jkrumbiegel commented 3 years ago

I see, and I can imagine people do this often just because the API differs a bit from Plots.jl

ffreyer commented 3 weeks ago

I guess jpeg is a wont-fix for us which leaves a better error for save(..., plot) as TODO?