首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gadfly:直接在浏览器中打开堆叠图?

Gadfly:直接在浏览器中打开堆叠图?
EN

Stack Overflow用户
提问于 2016-09-08 21:28:50
回答 1查看 290关注 0票数 1

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

代码语言:javascript
复制
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));

我写了一个函数来创建这样的图,这个函数创建了一个文件。对于想要使用此函数的人来说,这有点不直观,为什么此函数创建一个文件,而所有其他绘图函数的结果直接显示在浏览器中。

那么,是否可以调用一个函数(代替draw?)以便由网格定义的组合图直接显示在浏览器中,就像“普通”图一样?

EN

回答 1

Stack Overflow用户

发布于 2016-09-08 23:14:42

代码语言:javascript
复制
function as_temp_html(gadflyplot)
    thefilepath=tempname() * ".html"
    write(open(thefilepath,"w"),stringmime("text/html",gadflyplot))
    return thefilepath
end

您可以通过重新使用Gadfly's crossplatform "open_file" method在浏览器中打开此文件

代码语言:javascript
复制
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

编辑:现在答案使用了Gadfly独占的代码

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39392296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档