我正在following example工作并且悲惨地失败
# initialize the attractor
n = 1500
dt = 0.02
σ, ρ, β = 10., 28., 8/3
x, y, z = 1., 1., 1.
# initialize a 3D plot with 1 empty series
plt = path3d(1, xlim=(-25,25), ylim=(-25,25), zlim=(0,50),
xlab = "x", ylab = "y", zlab = "z",
title = "Lorenz Attractor", marker = 1)
# build an animated gif, saving every 10th frame
@gif for i=1:n
dx = σ*(y - x) ; x += dt * dx
dy = x*(ρ - z) - y ; y += dt * dy
dz = x*y - β*z ; z += dt * dz
push!(plt, x, y, z)
end every 10
我有模拟,我想要计算并经常绘制直方图,然后为所有直方图设置动画。这就是我迄今为止的玩具示例:
using Distributions
using Plots
Plots.gr()
p = rand(Normal(0,1), 10000)
myplot = Plots. histogram(p)
savefig("initial.png")
anim = @animate for i=1:10
p = rand(Normal(0,1), 10000)
push!(myplot, Plots.histogram(p))
end
gif(anim, "mygif.gif", fps = 1)
正如你可能会说的那样,我真的不知道这个@animate是如何工作的,我只是在猜测这里的语法。我知道我可以保存一堆PNG并稍后动画,但我想以这种方式尝试。
答案 0 :(得分:2)
anim = @animate for i=1:10
p = rand(Normal(0,1), 10000)
histogram(p)
end
gif(anim, "mygif.gif", fps = 1)
应该有用。