将Gadfly图表直接渲染到Gtk画布上

9

能否直接将Gadfly图形呈现到画布上?我想使用gtk开发一个Julia GUI,该GUI可以呈现Gadfly图形。

我希望实现以下类似的功能:

some_plot = plot(x=[1,2,3],y=[4,5,6])
draw(ctx::CairoContext, some_plot)

或者

draw(c::GtkCanvas, some_plot)

我的当前方法是保存PNG图像,然后加载该图像。显然不是最优解:

ctx = getgc(canvas)
canvas_w = width(canvas)
canvas_h = height(canvas)

save(ctx)
set_source_rgb(ctx,1,1,1)
rectangle(ctx,0,0,canvas_w,canvas_h)
fill(ctx)
restore(ctx)

some_plot = plot(x=[1,2,3],y=[4,5,6])
draw(PNG("myplot.png", 8inch, 4inch), some_plot)

save(ctx)
image = read_from_png("myplot.png")
w = image.width
h = image.height
translate(ctx, canvas_w/2, canvas_h/2)
scale(ctx, canvas_w/w, canvas_h/h)
translate(ctx, -0.5*w, -0.5*h)
set_source_surface(ctx, image, 0, 0)
paint(ctx)
restore(ctx)

谢谢你

1个回答

2
你应该查看Tim Holy的包Immerse,它可以通过我的包Plots来访问。Immerse创建Gadfly上下文,并将其呈现到Gtk画布上,还具有一些额外的交互功能。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接