Gif plot fails with BoundsError

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).

Looks like an issue with the plotlyjs backend. What happens if you run the code without that call (which is not part of the example)?

1 Like

The reason I was using plotly is that when I use the default (I think its gr), I got this error:

/home/milton/.julia/packages/GR/KGODl/src/../deps/gr/bin/gksqt: error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory
connect: Connection refused
GKS: can't connect to GKS socket application
Did you start 'gksqt'?

I found this issue on the Plots page:

I now managed to solve it by installing the qt5widgets library. Still, seems like a weird issue with the plotlyjs library. Should it be reported to them?

Thanks for the help by the way.

It’s probably an issue with Plots’ plotlyjs backend. It would be helpful if you could open an issue on Plots, also reporting your ]status of Plots and PlotlyJS and your versioninfo(). Thanks!

Okay, opened a new issue referencing error 489 which is similar but on windows and using a previous version of Julia.