Compose.jl
Compose.jl copied to clipboard
Is it possible use a png as a background for a plot?
I'd like to use a png as a background for a plot, in Compose and/or Gadfly. Is this currently possible?
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)))
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.
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
See: https://github.com/dcjones/Compose.jl/issues/140 and: https://github.com/dcjones/Compose.jl/pull/141
SVG backend works with bitmaps. just replace PNG in the example above with SVG