Compose.jl icon indicating copy to clipboard operation
Compose.jl copied to clipboard

Is it possible use a png as a background for a plot?

Open dlfivefifty opened this issue 8 years ago • 5 comments

I'd like to use a png as a background for a plot, in Compose and/or Gadfly. Is this currently possible?

dlfivefifty avatar Jan 14 '16 04:01 dlfivefifty

Yes that should be possible... here's an example that you should be able to adopt... it draws a circle behind a plot. Just replace the circle with an image and I think it should work.

using Gadfly,Compose
p = plot(x=1:10,y=rand(10));
c = circle(0.5,0.5,0.5);
draw(PNG("/home/tom/tmp.png", 4inch, 4inch), compose(context(), c, render(p)))

tbreloff avatar Jan 14 '16 13:01 tbreloff

How do you do images?

Sent from my iPhone

On 15 Jan 2016, at 00:47, Tom Breloff [email protected] wrote:

Yes that should be possible... here's an example that you should be able to adopt... it draws a circle behind a plot. Just replace the circle with an image and I think it should work.

using Gadfly,Compose p = plot(x=1:10,y=rand(10)); c = circle(0.5,0.5,0.5); draw(PNG("/home/tom/tmp.png", 4inch, 4inch), compose(context(), c, render(p))) — Reply to this email directly or view it on GitHub.

dlfivefifty avatar Jan 14 '16 14:01 dlfivefifty

Hmm nevermind... epic fail:

julia> b = bitmap("image/png", readbytes(open("/home/tom/tmp.png")), 0, 0, 4inch, 4inch)
Compose.Form{Compose.BitmapPrimitive{Tuple{Measures.Length{:cx,Int64},Measures.Length{:cy,Int64}},Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}}}([Compose.BitmapPrimitive{Tuple{Measures.Length{:cx,Int64},Measures.Length{:cy,Int64}},Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}}("image/png",UInt8[0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00  …  0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82],(0cx,0cy),101.6mm,101.6mm)],symbol(""))

julia> draw(PNG("/home/tom/tmp2.png", 4inch, 4inch), compose(context(), b, render(p)))
ERROR: Embedding bitmaps in Cairo backends (i.e. PNG, PDF, PS) is not supported.
 in draw at /home/tom/.julia/v0.4/Compose/src/cairo_backends.jl:790
 in drawpart at /home/tom/.julia/v0.4/Compose/src/container.jl:558
 in draw at /home/tom/.julia/v0.4/Compose/src/container.jl:434

tbreloff avatar Jan 14 '16 14:01 tbreloff

See: https://github.com/dcjones/Compose.jl/issues/140 and: https://github.com/dcjones/Compose.jl/pull/141

tbreloff avatar Jan 14 '16 14:01 tbreloff

SVG backend works with bitmaps. just replace PNG in the example above with SVG

bjarthur avatar Mar 03 '17 16:03 bjarthur