You can have Plots write the image as a MIME in-memory image and then in the Canvas draw update have Gtk load that image:
using Cairo
using Gtk
using Plots
const io = PipeBuffer()
histio(n) = show(io, MIME("image/png"), histogram(randn(n)))
function plotincanvas(h = 900, w = 800)
win = GtkWindow("Normal Histogram Widget", h, w) |> (vbox = GtkBox(:v) |> (slide = GtkScale(false, 1:500)))
Gtk.G_.value(slide, 250.0)
can = GtkCanvas()
push!(vbox, can)
set_gtk_property!(vbox, :expand, can, true)
@guarded draw(can) do widget
ctx = getgc(can)
n = Int(Gtk.GAccessor.value(slide))
histio(n)
img = read_from_png(io)
set_source_surface(ctx, img, 0, 0)
paint(ctx)
end
id = signal_connect((w) -> draw(can), slide, "value-changed")
showall(win)
show(can)
end
plotincanvas()
I am sure that there is also a way to transfer the image data directly, without show(), if you knew the underlying data formats. This method avoids any need for explicit conversions.