Hi,
I’m trying to run this simple example from the Plots library but it fails with BoundsError:
using Plots
plotlyjs()
# define the Lorenz attractor
mutable struct Lorenz
dt; σ; ρ; β; x; y; z
end
function step!(l::Lorenz)
dx = l.σ*(l.y - l.x) ; l.x += l.dt * dx
dy = l.x*(l.ρ - l.z) - l.y ; l.y += l.dt * dy
dz = l.x*l.y - l.β*l.z ; l.z += l.dt * dz
end
attractor = Lorenz((dt = 0.02, σ = 10., ρ = 28., β = 8//3, x = 1., y = 1., z = 1.)...)
# initialize a 3D plot with 1 empty series
plt = plot3d(1, xlim=(-25,25), ylim=(-25,25), zlim=(0,50),
title = "Lorenz Attractor", marker = 2)
# build an animated gif by pushing new points to the plot, saving every 10th frame
@gif for i=1:1500
step!(attractor)
push!(plt, attractor.x, attractor.y, attractor.z)
end every 10
and output:
ERROR: LoadError: BoundsError: attempt to access 0-element Array{PlotlyBase.GenericTrace{Dict{Symbol,Any}},1} at index [1]
Stacktrace:
[1] getindex at ./array.jl:729 [inlined]
[2] #restyle!#125 at /home/milton/.julia/packages/PlotlyBase/4sp9a/src/api.jl:151 [inlined]
[3] restyle!(::PlotlyBase.Plot{PlotlyBase.GenericTrace{Dict{Symbol,Any}}}, ::Int64, ::Dict{Symbol,Any}) at /home/milton/.julia/packages/PlotlyBase/4sp9a/src/api.jl:151
[4] #restyle!#5(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::PlotlyJS.SyncPlot, ::Int64, ::Dict{Symbol,Any}) at /home/milton/.julia/packages/PlotlyJS/CEJyh/src/display.jl:177
[5] restyle! at /home/milton/.julia/packages/PlotlyJS/CEJyh/src/display.jl:177 [inlined]
[6] _series_updated(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Series) at /home/milton/.julia/packages/Plots/47Tik/src/backends/plotlyjs.jl:32
[7] setxyz!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Tuple{Array{Float64,1},Array{Float64,1},Array{Float64,1}}, ::Int64) at /home/milton/.julia/packages/Plots/47Tik/src/utils.jl:877
[8] push!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Int64, ::Float64, ::Float64, ::Float64) at /home/milton/.julia/packages/Plots/47Tik/src/utils.jl:991
[9] push!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Float64, ::Float64, ::Float64) at /home/milton/.julia/packages/Plots/47Tik/src/utils.jl:956
[10] macro expansion at /home/milton/Code/Random Stuff/tutorials/julia/lorenz.jl:26 [inlined]
[11] top-level scope at /home/milton/.julia/packages/Plots/47Tik/src/animation.jl:163 [inlined]
[12] top-level scope at ./none:0
[13] include at ./boot.jl:326 [inlined]
[14] include_relative(::Module, ::String) at ./loading.jl:1038
[15] include(::Module, ::String) at ./sysimg.jl:29
[16] include(::String) at ./client.jl:403
[17] top-level scope at none:0
in expression starting at /home/milton/Code/Random Stuff/tutorials/julia/lorenz.jl:24
I don’t know what is the problem. I am new to Julia and I was expecting this to work as is (since it’s an example).