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:
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.
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).
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.