首页 > 解决方案 > 如何在不关闭 Julia 环境的情况下清理 Plots (GR)

问题描述

我正在调试一个脚本(Plots.jlGKS QtTerm后端一起使用)。所以我多次运行脚本。当我从终端运行它时bash> julia pointPlacement.jl,初始化 Julia 和 Plots.jl 需要很长时间(与 python 相比,这是一个很大的不便)。因此,我宁愿让 Julia 保持打开状态并从内部运行脚本,例如julia> include( "pointPlacement.jl" )

grid = [ [ix*0.01 iy*0.01] for ix=1:100, iy=1:100 ]
grid = vcat(ps...)

centers = hexGrid( 2, 0.2 )

using Plots
display(scatter!( grid[:,1], grid[:,2], markersize = 1, markerstrokewidth = 0, aspect_ratio=:equal ))
display(scatter!( centers[:,1], centers[:,2], markersize = 2, markerstrokewidth = 0, aspect_ratio=:equal ))

问题是地块堆积。这是9次运行之后。应该只有 2 个数据集,而不是 18 个:

在此处输入图像描述

我想关闭(杀死,摧毁)他们

如果我这样删除!,它会有所帮助

display(scatter( grid[:,1], grid[:,2], markersize = 1, markerstrokewidth = 0, aspect_ratio=:equal ))
display(scatter!( centers[:,1], centers[:,2], markersize = 2, markerstrokewidth = 0, aspect_ratio=:equal ))

但是,我仍然担心一些垃圾(以前的数字)会留在内存中,并且在我运行脚本 100 倍后 Julia 会崩溃。因此,我想在每次运行脚本时调用一些函数,如clear(), flush(), closeAll()... 或其他...

标签: juliaplots.jl

解决方案


删除!具有您想要的效果 - 如果您scatter再次调用,情节就消失了,并且它不在后台的某个地方。

如果您愿意,您可以将绘图存储在变量中并“为了安全”将其覆盖,即

p = scatter(...)
scatter!(p, ...)

...你的阴谋论点在哪里。这将显式覆盖p每个include.


推荐阅读