作图命令不在最后一行就不能输出图片?!

例如以下代码,作图代码最后多了一行a = 1,结果就不能输出图片了。Julia的这种特性是何苦呢?怎么能让它像matlab一样,运行结束,所有图都保留?

import LinearAlgebra
import Plots
import Random

Random.seed!(314)

# number of clients
m = 12
# number of facility locations
n = 5

# Clients' locations
Xc, Yc = rand(m), rand(m)

# Facilities' potential locations
Xf, Yf = rand(n), rand(n)

# Distance
c = zeros(m, n)
for i in 1:m
    for j in 1:n
        c[i, j] = LinearAlgebra.norm([Xc[i] - Xf[j], Yc[i] - Yf[j]], 2)
    end
end

Plots.scatter(
    Xc,
    Yc;
    label = "Clients",
    markershape = :circle,
    markercolor = :blue,
)
Plots.scatter!(
    Xf,
    Yf;
    label = "Facility",
    markershape = :square,
    markercolor = :white,
    markersize = 6,
    markerstrokecolor = :red,
    markerstrokewidth = 2,
)


a = 1

先好好看文档吧,输出多少张都行

using Plots
x=0.0:0.01:2pi
for ii in 1:5
    display(plot(x,sin.(ii.*x))
end
3 个赞