使用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));我写了一个函数来创建这样的图,这个函数创建了一个文件。对于想要使用此函数的人来说,这有点不直观,为什么此函数创建一个文件,而所有其他绘图函数的结果直接显示在浏览器中。
那么,是否可以调用一个函数(代替draw?)以便由网格定义的组合图直接显示在浏览器中,就像“普通”图一样?
发布于 2016-09-08 23:14:42
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在浏览器中打开此文件
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独占的代码
https://stackoverflow.com/questions/39392296
复制相似问题