Code
using Distributions,GLMakie,Random
Random.seed!(343434)
TaskLocalRNG()
通过contour:levels
参数控制曲线的范围
levels=1
则只绘制出一条等位线
using Distributions,GLMakie,Random
Random.seed!(343434)
TaskLocalRNG()
=[3,2]
μ=[1 -1.5;-1.5 4]
Σ=MvNormal(μ,Σ)
d=range(0,6,100)
xs=range(-4,7,100)
ys= [pdf(d, [i, j]) for i in xs, j in ys]
dens_mvnormal =rand(d,100) rand_sample
2×100 Matrix{Float64}:
2.04893 3.14939 2.04006 2.96766 3.14777 … 2.9465 2.47969 3.17612
3.31172 2.04522 2.43717 1.83891 1.69139 2.44297 0.862216 0.327061
function plot_func(fig,idx,levels=1)
=Axis(fig[1,idx], xlabel=L"X", ylabel=L"Y")
axBox(fig[1,idx];color = (:orange,0.1))
scatter!(ax,rand_sample;marker=:circle,markersize=10,color=(:green,0.1),
=1,strokecolor=:black)
strokewidthcontour!(ax,xs, ys,dens_mvnormal;levels=levels,linewidth=1)
end
function plot_mvnormal()
=Figure(resolution=(800,400))
figplot_func(fig,idx,levels) for (idx,levels) in enumerate([1,16])]
[
figend
plot_mvnormal()