Julia 牛虻:直接在浏览器中打开堆叠图?

Julia 牛虻:直接在浏览器中打开堆叠图?,julia,gadfly,Julia,Gadfly,使用Gadfly,可以在网格中组合绘图,并将组合绘图保存在文件中: using Gadfly, Compose x=1:0.1:5; grid = Array(Compose.Context, (2, 2)); grid[1,1] = render(plot( x=x, y = x, Geom.line)); grid[1,2] = render(plot( x=x, y = x.^2, Geom.line)); grid[2,1] = render(plot( x=x, y = log(x)

使用Gadfly,可以在网格中组合绘图,并将组合绘图保存在文件中:

using Gadfly, Compose

x=1:0.1:5;
grid = Array(Compose.Context, (2, 2));
grid[1,1] = render(plot( x=x, y = x, Geom.line));
grid[1,2] = render(plot( x=x, y = x.^2, Geom.line));
grid[2,1] = render(plot( x=x, y = log(x), Geom.line));
grid[2,2] = render(plot( x=x, y = sqrt(x), Geom.line));
draw(SVG("example.svg", 100mm, 100mm),  gridstack(grid));
我写了一个函数来创建这样一个绘图,这个函数创建一个文件。对于想要使用此函数的人来说,这有点不直观,为什么此函数会创建一个文件,而具有单个打印的所有其他打印函数的结果会直接显示在浏览器中

因此,是否可以调用函数(代替
绘图
?),以便网格定义的组合图与“普通”图一样直接显示在浏览器中

您可以在浏览器中重新使用以下命令打开此文件:


编辑:现在答案使用Gadfly专有代码

谢谢。好的,看来除了创建一个临时html文件并自己在浏览器中打开它之外,别无选择。我发现牛虻对此有几乎相同的机制(参见)。如果您将Gadfly的
open\u browser\u window
功能更改为
open\u file
功能,并使用Gadfly存储库中的链接替换到绘图包的链接,我将接受您的回答。如果一个绘图包也提供了功能,那么使用一个绘图包来显示另一个绘图包的绘图是没有意义的。有一些工具可以在不写入磁盘的情况下执行同样的操作(进程管道、WebSocket),但据我所知,这些工具还没有达到您的要求(实时编辑和更新代码和绘图,或从浏览器获取更新的结果)。不过,请看一下……可能会很有用
function as_temp_html(gadflyplot)
    thefilepath=tempname() * ".html"
    write(open(thefilepath,"w"),stringmime("text/html",gadflyplot))
    return thefilepath
end
function open_file(filename)
    if is_apple()
        run(`open $(filename)`)
    elseif is_linux() || is_bsd()
        run(`xdg-open $(filename)`)
    elseif is_windows()
        run(`$(ENV["COMSPEC"]) /c start $(filename)`)
    else
        warn("Showing plots is not supported on OS $(string(Compat.KERNEL))")
    end
end