我正在从以下示例开始工作并且失败了
# 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
Run Code Online (Sandbox Code Playgroud)
我有一些模拟,我想每隔一段时间计算和绘制一个直方图,然后为所有这些直方图设置动画。到目前为止,这是我所拥有的玩具示例:
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)
Run Code Online (Sandbox Code Playgroud)
正如您可能会说的,我真的不明白这个@animate 是如何工作的,我只是在猜测这里的语法。我知道我可以保存一堆 PNG,然后再制作动画,但我想以这种方式尝试。
anim = @animate for i=1:10
p = rand(Normal(0,1), 10000)
histogram(p)
end
gif(anim, "mygif.gif", fps = 1)
Run Code Online (Sandbox Code Playgroud)
应该管用。
| 归档时间: |
|
| 查看次数: |
1101 次 |
| 最近记录: |