0

I am creating math questions with geometric components such as triangles and rectangles and think plotly would be a nice lightweight mechanism for creating these plots. But I need these plots to be static (non-interactive). I assume I can save them as PNGs. I am hoping to generate them interactively in the browser to make it harder for content to be misappropriated.

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.") 
Francis Smart
  • 3,875
  • 6
  • 32
  • 58
  • Do you mind using PlotlyJS backend instead? Because you can achieve this easily with PlotlyJS. – hckr Apr 04 '18 at 23:16
  • "Plotly" backend does not support saving "png" or any other image formats. I believe `Plotly` package is used to interact with Plotly Cloud. I think you should switch to `PlotlyJS` instead. – hckr Apr 04 '18 at 23:42

1 Answers1

0

Think I figured it out.

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}")

It is a little hacky but adds the staticPlot: true attribute to the end of the function.

Francis Smart
  • 3,875
  • 6
  • 32
  • 58