# Different behaviour when plotting one vs many ODE solutions

**URL:** <https://discourse.julialang.org/t/different-behaviour-when-plotting-one-vs-many-ode-solutions/114248>\
**Category:** General Usage\
**Tags:** plotting, ode\
**Created:** [May 14, 2024, 12:57pm UTC](https://discourse.julialang.org/t/different-behaviour-when-plotting-one-vs-many-ode-solutions/114248 "2024-05-14T12:57:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dbox/32/209217_2.png) [@dbox](https://discourse.julialang.org/u/dbox)\
**Post date:** [May 14, 2024, 12:57pm UTC](https://discourse.julialang.org/t/different-behaviour-when-plotting-one-vs-many-ode-solutions/114248/1 "2024-05-14T12:57:43Z")

</div>

When taking a slice of the result of `solve(ODEProblem)`, slices with a range (e.g. `sol[1:3]` return the time series as well, whereas a single element `sol[1]` only returns the y-values.  
I want to be able to plot either one or several solutions in the same line and not sure how to do that.

If I want to plot a number of solutions, I can do:  
`plot(sol[1:n])`

If I want to plot just one, I can do this:  
`plot(sol.t, sol[1,:])`

`plot(sol.t, sol[1:n,:])` gives:  
`ERROR: Expects 8 elements in each col of y, found 3.`

and `plot(sol[1])` doesn’t plot with the time steps as x values.

Any help appreciated!

Example code below:

```julia
using Random, Distributions, OrdinaryDiffEq, Plots
function fun(f, p, t)
    df .= -p[:A] * f
    df
end
rng = MersenneTwister(42)
p = Dict(:A => rand(5,5))
x0 = rand(rng, Uniform(1,10), 5)
tspan=(0,1)
pr = NamedTuple(p)
prob = ODEProblem(fun, x0, tspan, pr)
sol = solve(prob, Tsit5())
# Compare:
# plot(sol[1:3])
#plot(sol.t, sol[1])
# plot(sol.t,sol[1:3,:])
# plot(sol[1])
```

---

<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:** [May 14, 2024, 1:32pm UTC](https://discourse.julialang.org/t/different-behaviour-when-plotting-one-vs-many-ode-solutions/114248/2 "2024-05-14T13:32:00Z")

</div>

It plots an interpolation by default.
