当 运行 来自 Plots.jl 中的终端时,情节 window 出现

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

我正在使用 Plots.jl 和默认后端来绘制图像并保存图形。

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

这与 Juno IDE 完美配合。但是我的最终代码预计会在终端中 运行 。当我尝试 运行 终端中的相同代码时,它变得非常慢,并且在每个图中我都看到 GKS QtTerm window 出现并消失了片刻。有没有办法禁用这个 window?

编辑: 这是我的 运行 时间结果。

在原子朱诺中:

在Windows命令中:

为了将性能提高 150 倍,将空设备设置为 gr 输出。

ENV["GKSwstype"]="nul"

这需要在初始化 gr() 后端之前完成。

这是我机器上的时间:

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

产量:

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

产量:

0.016462 seconds (24.22 k allocations: 877.680 KiB)

如此简单,速度提高 150 倍!

补充说明。如果您想最大程度地减少在 Julia sysismage 中编译 Plots.jl 的第一个绘图的时间。这是我的另一个 SO 答案,解释了如何