# Makie recipe to plot ODESolution of DifferentialEquations.jl?

**URL:** <https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879>\
**Category:** Visualization\
**Tags:** plotting, makie, recipe, ordinarydiffeq\
**Created:** [November 6, 2023, 9:52pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879 "2023-11-06T21:52:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Post date:** [November 6, 2023, 9:52pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/1 "2023-11-06T21:52:26Z")

</div>

Related to [this question](https://discourse.julialang.org/t/easy-way-to-plot-a-circle-given-as-a-vector-of-vectors-pointwise-as-line-plot/104574/1).

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

I tried

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

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 7, 2023, 12:18am UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/2 "2023-11-07T00:18:35Z")

</div>

There is none that is shipped in the package.

---

<div class="post-metadata">

**Author:** ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Post date:** [November 7, 2023, 9:33am UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/3 "2023-11-07T09:33:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 7, 2023, 10:39pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/4 "2023-11-07T22:39:15Z")

</div>

Maybe [this GMT example](https://www.generic-mapping-tools.org/GMTjl_doc/Interoperability/index.html#differentialequations) is similar to what you want?

---

<div class="post-metadata">

**Author:** ![hisacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hisacro/32/202631_2.png) [@hisacro](https://discourse.julialang.org/u/hisacro)\
**Post date:** [November 8, 2023, 9:36am UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/5 "2023-11-08T09:36:22Z")

</div>

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

```julia
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](https://juliadynamics.github.io/DynamicalSystems.jl/dev/tutorial/#Example:-Lorenz96)  
and [interactive trajectory](https://juliadynamics.github.io/DynamicalSystems.jl/dev/visualizations/#Example-1:-interactive-trajectory-animation)

---

<div class="post-metadata">

**Author:** ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Post date:** [November 8, 2023, 12:22pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/6 "2023-11-08T12:22:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 8, 2023, 12:45pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/7 "2023-11-08T12:45:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jo-ap](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jo-ap/32/44449_2.png) [@jo-ap](https://discourse.julialang.org/u/jo-ap)\
**Post date:** [February 13, 2024, 2:26pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/8 "2024-02-13T14:26:46Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Post date:** [January 22, 2025, 11:50pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/9 "2025-01-22T23:50:45Z")

</div>

How wide is the makie support in SciML now? Is there an overview?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 22, 2025, 11:58pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/10 "2025-01-22T23:58:16Z")

</div>

There is now a recipe in there but it’s not the most widely used. It needs some docs and some battle testing.

---

<div class="post-metadata">

**Author:** ![homocomputeris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/homocomputeris/32/8933_2.png) [@homocomputeris](https://discourse.julialang.org/u/homocomputeris)\
**Post date:** [January 22, 2025, 11:59pm UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/11 "2025-01-22T23:59:57Z")

</div>

Can you point to some minimal instructions for battle testing? Or is it simply

```julia
using CairoMakie

plot(u)

```

?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 23, 2025, 12:28am UTC](https://discourse.julialang.org/t/makie-recipe-to-plot-odesolution-of-differentialequations-jl/105879/12 "2025-01-23T00:28:55Z")

</div>

Minimal and battle testing are exact opposites… the whole point is to try everything. Plot the solution with bigfloats, taylordiff, phase plots, complex numbers, … just everything.
