运行Plots的example源码出错


#1

这是Plots里面给出的例子,我按源码执行出错,不知道哪里有问题

n = 1500
dt = 0.02
σ, ρ, β = 10., 28., 8/3
x, y, z = 1., 1., 1.
using Plots
# 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

ERROR: LoadError: UndefVarError: y not defined
Stacktrace:
[1] macro expansion at /home/rzhli/Documents/Julia/example:13 [inlined]
[2] top-level scope at /home/rzhli/.julia/packages/Plots/rmogG/src/animation.jl:155 [inlined]
[3] top-level scope at ./none:0
in expression starting at /home/rzhli/Documents/Julia/example:12


#2

鉴于这个问题出现得太频繁,我加了一条Q&A在 入门指引 3.5


#3

多谢指点,在

@gif for i=1:n

后面加上

global x,y,z;

就可以了,但又给出新错误:
LoadError: IOError: could not spawn ffmpeg -v 0 -i /tmp/tmpEZsg2a/%06d.png -vf palettegen=stats_mode=diff -y /tmp/tmpEZsg2a/palette.bmp: no such file or directory (ENOENT)


#4

善用论坛的搜索功能