We are using docker and we wait to avoid local X windows installation. Display() tries to use xdb-show, which we cannot have. We want to save the contents of the figure in html (it’s exactly the same .html that gets created in /tmp/ when calling display()), so how can this be achieved? We tried savefig etc., but we can’t see to find a way to save the plot in html. Thanks a lot!
Hey, thanks for the reply. The problem is that saving to png will remove the “interactivity” that display() offers. My code is the one below…
using DelimitedFiles
using Plots
using Statistics
# parse output of execution
M = readdlm("./run.log", ',', Float64, skipstart=1);
# select plotly as backend and open figure
plotly(ticks=:native)
plt = plot();
# Binet
F(n) = convert( Int64, round(((1+sqrt(big(5)))^n-(1-sqrt(big(5)))^n)/(sqrt(big(5))*big(2)^n),digits=0))
# draw different curve for differet number of processors
npList = unique(M[:,1]);
for i in 1:length(npList)
ind = npList[i] .== M[:,1];
x = M[ind,2]
@assert all( (F.(x) - M[ind,3]) .== 0 )
y = vec(mean(M[ind,5:end], dims=2))
plot!(plt, x, y, label="np = $(npList[i])",
markershape=:xcross)
end
# fix plot attributes & display
plot!(title = "Time to compute fib(n)", xlabel = "n", ylabel = "time (sec)",
xscale = :log, yscale = :log)
display(plt);
So diplay() offers interactivity with the plot, opposed to the png. So when running this, without having X windows installed, you get an error that says that xdb was not able to load /tmp/randomfile.html. That html file is what I want to save in a timely manner!
I’m not sure what you’re suggesting is even possible but In the meantime if you want interactivity in the browser you can use PlotlyJS which will work quite well for things like panning, zooming etc
As an example, here: Work with Plotly you can see how a plotly generated plot can be inserted in a webpage, you don’t have to use Franklin, you could just imitate the procedure
For static/non-interactive plots, you can also try to save to SVG and then just render it in a browser directly, or embed it in a trivial HTML (depending on your application).
What I frequently do is to, first, suppress the need of a X server, using:
ENV["GKSwstype"]="nul"
Then I save the figures in pdf format (sometimes automatically copy it from the server to the machine where I am working). Most pdf readers update the files automatically when they are modified. I usually do this even with a X server available, because the rendering of the figure assumes exactly its final appearance.