# Gif plot fails with BoundsError

**URL:** <https://discourse.julialang.org/t/gif-plot-fails-with-boundserror/23645>\
**Category:** New to Julia\
**Created:** [April 29, 2019, 12:19pm UTC](https://discourse.julialang.org/t/gif-plot-fails-with-boundserror/23645 "2019-04-29T12:19:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mllera14](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mllera14/32/7967_2.png) [@mllera14](https://discourse.julialang.org/u/mllera14)\
**Post date:** [April 29, 2019, 12:19pm UTC](https://discourse.julialang.org/t/gif-plot-fails-with-boundserror/23645/1 "2019-04-29T12:19:34Z")

</div>

Hi,

I’m trying to run this simple example from the Plots library but it fails with BoundsError:

```julia
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:

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

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [April 29, 2019, 6:08pm UTC](https://discourse.julialang.org/t/gif-plot-fails-with-boundserror/23645/2 "2019-04-29T18:08:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mllera14](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mllera14/32/7967_2.png) [@mllera14](https://discourse.julialang.org/u/mllera14)\
**Post date:** [April 30, 2019, 9:59am UTC](https://discourse.julialang.org/t/gif-plot-fails-with-boundserror/23645/3 "2019-04-30T09:59:20Z")

</div>

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

```julia
/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:

[https://github.com/JuliaPlots/Plots.jl/issues/1649](https://github.com/JuliaPlots/Plots.jl/issues/1649)

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.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [April 30, 2019, 10:16am UTC](https://discourse.julialang.org/t/gif-plot-fails-with-boundserror/23645/4 "2019-04-30T10:16:47Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mllera14](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mllera14/32/7967_2.png) [@mllera14](https://discourse.julialang.org/u/mllera14)\
**Post date:** [April 30, 2019, 10:41am UTC](https://discourse.julialang.org/t/gif-plot-fails-with-boundserror/23645/5 "2019-04-30T10:41:57Z")

</div>

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