在Julia Static中使用plotly后端制作Plots

问题描述 投票:0回答:1

我用几何组件(如三角形和矩形)创建数学问题,并认为plotly将是一个很好的轻量级机制来创建这些图。但我需要这些图是静态的(非交互式)。我想我可以将它们保存为PNGs。我希望在浏览器中以交互方式生成它们,以使内容更难被盗用。

using Plots
x = 1:10; y = rand(10,2) # 2 columns means two lines
plotly() # Set the backend to Plotly
plot(x,y,title="This is my static plot.") 
julia plots.jl
1个回答
0
投票

想想我明白了。

using Plots
x = 1:10; y = rand(10,2) # 2 columns means two lines
plotly() # Set the backend to Plotly
z = plot(x,y,title="This is my static plot.") 

function saveHTML(x, file; attributes=[]) 
  savefig(x , file)

  for i in attributes 
    s = replace(readstring(file), ");", ",$i);")
  end

  open(file, "w") do f
    write(f, s)
  end
end

saveHTML(z , "Z:/Temp/z.html", attributes="{staticPlot: true}")

这有点hacky但是将staticPlot: true属性添加到函数的末尾。

© www.soinside.com 2019 - 2024. All rights reserved.