Plots saved to file loose colour

I’m saving Gadfly plots as PNG but the colour is stripped from them, making them useless. The code looks like:

using DataFrames, Gadfly, Cairo
layers = Plot[]
for protein in proteins
  l = plot(f4p, x=protein, color=:dose, Geom.histogram)
  push!(layers, l)
end
layers = reshape(layers, 2, 2)
h = gridstack(layers)
display(h)
fn = "$(patient).png"
h |> PNG(fn)

I get the same for PNG, SVG and PDF. Any suggestions gratefully appreciated.

Here is what the plots look like in the plot window:

Here is what the saved PNG looks like:

i can’t run your exact code because you haven’t posted proteins, but when i run the histogram example in the gadfly gallery and save it to PNG it comes out just fine.

note that in your example not all the color is lost as the swatches in the legend are intact.

when posting bugs like this it’s always a good idea to let us know what OS you’re using, julia version, gadfly & compose version, etc.

i’m using mac osx, julia 1.8, and master of gadfly and compose.

What happens if you adjust the binning?

My theory here is that the edges are grey or black and they are overwhelming the underlying color when rendered or rastered.

Thanks for taking a look at this!

I originally noticed the problem on my M1 Mac (OSX 12.6) but I’ve now reproduced it on linux as well. I’m using julia 1.8.2 and have updated all packages. Here is a stand alone code that demonstrates the problem.

using DataFrames, Gadfly, Cairo, Random

rd(m) = m .+ 100*randn(100) 
f1 = DataFrame(BCL2=rd(500), BCLxL=rd(500), MCL1=rd(500), NOXA=rd(500), dose="0mg")
f2 = DataFrame(BCL2=rd(700), BCLxL=rd(700), MCL1=rd(700), NOXA=rd(700), dose="200mg")
f4p = vcat(f1, f2)

layers = Plot[]
for protein in [:MCL1, :NOXA, :BCLxL, :BCL2]
  l = plot(f4p, x=protein, color=:dose, Geom.histogram)
  fn = "$(string(protein)).png"
  push!(layers, l)
  l |> PNG(fn)
end
layers = reshape(layers, 2, 2)
h = gridstack(layers)
display(h)
fn = "broken.png"
h |> PNG(fn)

If I save the individual plots they are fine, it’s only after stacking that it breaks (which explains why I haven’t had this problem before).

It looks like a defect.

The code I posted in my other response has fewer bins, yet the problem persists. Interestingly, it displays fine in the editor plot window. I can then save that plot to a file and that file is fine.

Here is the detailed status of my linux environment.

(base) [thomas.e@vc7-shared ~]$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.2 (2022-09-29)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(v1.8) pkg> status
Status `/stornext/Home/data/allstaff/t/thomas.e/.julia/environments/v1.8/Project.toml`
  [c7e460c6] ArgParse v1.1.4
  [336ed68f] CSV v0.10.4
  [159f3aea] Cairo v1.0.5
  [5ae59095] Colors v0.12.8
  [863f3e99] Comonicon v1.0.0
  [bf9813a8] Cyton v0.1.0 `https://github.com/cyton-dynamics/cyton.toolkit.git#globalagents`
  [1b08a953] Dash v1.1.2
  [1b08a953] DashBootstrapComponents v1.2.1
  [a93c6f00] DataFrames v1.4.1
  [31c24e10] Distributions v0.25.76
  [587475ba] Flux v0.13.6
  [186bb1d3] Fontconfig v0.4.0
  [c91e804a] Gadfly v1.3.4
  [4c0ca9eb] Gtk v1.2.2
⌅ [cd3eb016] HTTP v0.9.17
  [682c06a0] JSON v0.21.3
  [2fda8390] LsqFit v0.13.0
  [d96e819e] Parameters v0.12.3
  [f0f68f2c] PlotlyJS v0.18.10
  [f45a3650] PosDefManifold v0.5.0
  [df47a6cb] RData v1.0.0
  [2913bbd2] StatsBase v0.33.21
  [24678dba] TSne v1.3.0
  [8bb1440f] DelimitedFiles
  [9a3f8284] Random
  [9e88b42a] Serialization
  [10745b16] Statistics
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`

definitely a bug. i can now reproduce. open an issue on the gadfly github repo so we can track.