plot window showing up when run from terminal in Plots.jl

564 views Asked by At

I'm using Plots.jl with the default backend to plot an image and save the figure.

using Plots: plot, savefig
plot(rangex,rangey,some_image,xticks,yticks,...);
savefig("name.jpg");

this works perfectly fine with Juno IDE. But my final code is expected to run in the terminal. When I try to run the same code in terminal it becomes super slow and in each plot I see a GKS QtTerm window appear and disappear for a moment. Is there a way to disable this window?

EDIT: Here are my runtime results.

In Atom Juno:

  • starting julia + loading libraries & functions took about 36s
  • doing 100 plot iterations took about 55s
  • total of 91 seconds.

In Windows cmd:

  • starting julia + loading libraries & functions took about 21s
  • doing 100 plot iterations took about 284 seconds
  • total of 305 seconds.
1

There are 1 answers

0
Przemyslaw Szufel On BEST ANSWER

For the 150x increase in the performance set null device as the gr output.

ENV["GKSwstype"]="nul"

This needs to be done before initializing the gr() backend.

Here are the times on my machine:

using Plots
gr()
savefig(plot(rand(10)),"myplot.png")
@time savefig(plot(rand(10)),"myplot.png");

yields:

2.388764 seconds (25.38 k allocations: 936.133 KiB)
using Plots
ENV["GKSwstype"]="nul"
gr()
savefig(plot(rand(10)),"myplot.png")
@time savefig(plot(rand(10)),"myplot.png");

yields:

0.016462 seconds (24.22 k allocations: 877.680 KiB)

Eeasy as that and 150x times faster!

Addtional note. If you want to minimize the time to the first plot compile Plots.jl inside your Julia sysismage. Here is my other SO answer explaining how Why julia takes long time to import a package?