Makie recipe to plot ODESolution of DifferentialEquations.jl?

Related to this question.

Is there a recipe to plot the DiffEq solution components against time?

I tried

Makie.convert_arguments(sol::ODESolution) = (sol.t, [[v[1] for v in sol.u], [[v[2] for v in sol.u]]])

but it plots solution components against each other.

1 Like

There is none that is shipped in the package.

As there is none, I would really appreciate advice how to implement one, because the Makie docs on recipes are a bit confusing.

Maybe this GMT example is similar to what you want?

1 Like

Is there a recipe to plot the DiffEq solution components against time?

unsure is this what you want, here’s how I plotted for 4 degree of freedom system - the function rotor in mine returns SVector{4}(du1,du2,du3,du4)

prob = ODEProblem(rotor, u0, times, params)
sol1 = solve(prob, AutoVern7(Rodas5()), dt = .005)
T = range(0,8000,length=500)  
# for plotting time series for 3rd variable
GLMakie.plot(T, sol1(T)[3,:], xlim=(0,8000))

you also can try DynamicalSystems.ji’s trajectory function example
and interactive trajectory

I’m still confused how to pack it into a recipe.

You need something like this:
Makie.convert_arguments(p::Makie.PointBased, sol::ODESolution) = convert_arguments(p, sol.t, [[v[1] for v in sol.u], [[v[2] for v in sol.u]]])
Not sure if this will work, you have to supply a minimal working example.

We’re pretty close to pin down how Makie should do recipes in the future and then revamp the docs accordingly.

5 Likes

I’m also confused how recipes and argument conversion work and would be happy to see some more examples and detailed explanations in the Docs.
However, for plotting multidimensional solutions, I find it convenient to use series. Here is a MWE with what I use:

using DifferentialEquations
using GLMakie

function f!(du, u, p, t)
  x, y = u
  α, β, γ, δ = p
  du .= [α*x - β*x*y, δ*x*y - γ*y]
  nothing
end

prob = ODEProblem(f!, [0.1, 0.1], (0.0, 25.0), (α = 1, β = 1.5, γ = 1, δ = 2))
sol = solve(prob, saveat=0.1)

# plot solution using series 
# 1: manually
GLMakie.series(sol.t, hcat(sol.u...); labels=["x", "y"])
axislegend()

# 2: convert arguments
Makie.convert_arguments(T::Type{<: Series}, sol::ODESolution) =  Makie.convert_arguments(T, sol.t, hcat(sol.u...))
GLMakie.series(sol; labels=["x", "y"])
axislegend()
2 Likes