How to animate multiple stochastic processes with GLMakie

I would like to animate a stochastic process with GLMakie. I have two related questions. First, in the code below, how do I fix the conversion error? Second, how can I programatically generate lines based on the number of columns in the matrix evidence? The example below has two columns, but there could be fewer or more columns.

Thank you.

Code

using GLMakie
using SequentialSamplingModels 

# simulate the decision process
model = RDM()
# evidence is a sample by choice matrix
times, evidence = simulate(model)

idx = Observable(1)

# setup plot accumulator for choice 1
ys_1 = @lift(evidence[$idx,1])
# setup plot accumulator for choice 2
ys_2 = @lift(evidence[$idx,2])

fig = lines(times, ys_1, color = :blue, linewidth = 4,
    axis = (title = @lift("t = $(round(times[$idx], digits = 1))"),))
lines!(times, ys_2, color = :red, linewidth = 4)

indices = 1:length(times)
record(fig, "time_animation.mp4", indices;
        framerate = length(times)) do i
    idx[] = i
end

Error

Summary
ERROR: ArgumentError:     Conversion failed for Lines (With conversion trait PointBased()) with args: Tuple{Vector{Float64}, Float64} .
    Lines requires to convert to argument types Tuple{AbstractVector{<:Union{Point2, Point3}}}, which convert_arguments didn't succeed in.
    To fix this overload convert_arguments(P, args...) for Lines or PointBased() and return an object of type Tuple{AbstractVector{<:Union{Point2, Point3}}}.`

Stacktrace:
 [1] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…}, recursion::Int64)
   @ Makie ~/.julia/packages/Makie/GtFuI/src/interfaces.jl:240
 [2] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…}, recursion::Int64)
   @ Makie ~/.julia/packages/Makie/GtFuI/src/interfaces.jl:233
 [3] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…})
   @ Makie ~/.julia/packages/Makie/GtFuI/src/interfaces.jl:213
 [4] (Lines)(user_args::Tuple{Vector{Float64}, Observable{Float64}}, user_attributes::Dict{Symbol, Any})
   @ Makie ~/.julia/packages/Makie/GtFuI/src/interfaces.jl:271
 [5] _create_plot(::Function, ::Dict{Symbol, Any}, ::Vector{Float64}, ::Vararg{Any})
   @ Makie ~/.julia/packages/Makie/GtFuI/src/figureplotting.jl:316
 [6] lines(::Vector{Float64}, ::Vararg{Any}; kw::@Kwargs{color::Symbol, linewidth::Int64, axis::@NamedTuple{…}})
   @ MakieCore ~/.julia/packages/MakieCore/UpNdE/src/recipes.jl:436
 [7] top-level scope
   @ ~/.julia/dev/sandbox/turing_predict/example.jl:77
Some type information was truncated. Use `show(err)` to see complete types.

I don’t understand what you’re trying to plot as a line, as you’re passing a vector of times for x but a scalar for y, that’s also what the error message means. Probably your indexing is off and you expected to get a vector?

For the other question, you could try the series recipe which is a bit of convenience on top of lines for multiple time series.

Thanks for your reply. series seems to be what I neeed, but I still can’t figure out how to integrate it properly with the animation. It works correctly without the animation:

using GLMakie
using SequentialSamplingModels
# simulate the decision process
model = RDM()
times, evidence = simulate(model)
fig, ax, sp = series(times, evidence')
axislegend(ax)

However, I get a similar error for the animation:

using GLMakie
using SequentialSamplingModels 

# simulate the decision process
model = RDM()
times, evidence = simulate(model)
evidence = evidence'
idx = Observable(1)

# setup plot accumulator for choice 1
ys_1 = @lift(evidence[:,$idx])

fig = series(times, ys_1, color = :blue, linewidth = 4,
    axis = (title = @lift("t = $(round(times[$idx], digits = 1))"),))

indices = 1:length(times)
record(fig, "time_animation.mp4", indices;
        framerate = length(times)) do i
    idx[] = i
end

Any ideas?