# Plotting Multiple ODE Trajectories on the Same Plot

**URL:** <https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387>\
**Category:** New to Julia\
**Created:** [September 16, 2022, 8:10pm UTC](https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387 "2022-09-16T20:10:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoshi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoshi/32/38259_2.png) [@yoshi](https://discourse.julialang.org/u/yoshi)\
**Post date:** [September 16, 2022, 8:10pm UTC](https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387/1 "2022-09-16T20:10:05Z")

</div>

I have a bunch of ODE simulation outputs. I’m having trouble plotting all the solutions on the same plot.

I can do something like the following code. But do I need to reshape the entire simulation output to do this?  
`plot([sim[1].t,sim[2].t],[sim[1][3,:],sim[2][3,:]])`  
Is there another way to accomplish plotting the simulations on the same plot? I tried looping through `plot!` but this didn’t work for me.

Context for solution below: use in `vars` parameter in plot.

---

<div class="post-metadata">

**Author:** ![liamfdoherty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liamfdoherty/32/24516_2.png) [@liamfdoherty](https://discourse.julialang.org/u/liamfdoherty)\
**Post date:** [September 16, 2022, 8:45pm UTC](https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387/2 "2022-09-16T20:45:09Z")

</div>

If you have simulations generated from an [ensemble simulation](https://diffeq.sciml.ai/stable/features/ensemble/#Example-1:-Solving-an-ODE-With-Different-Initial-Conditions), you can just call `plot(sim)` as shown in the linked example. This is helpful if you are running many instances of the same model, but with, e.g., varying parameters. Otherwise, I don’t see a reason why multiple calls to `plot!` wouldn’t work. Do you have part of your script that you could share? That might help find the issue.

---

<div class="post-metadata">

**Author:** ![yoshi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoshi/32/38259_2.png) [@yoshi](https://discourse.julialang.org/u/yoshi)\
**Post date:** [September 16, 2022, 9:09pm UTC](https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387/3 "2022-09-16T21:09:29Z")

</div>

Okay when I get back to my computer I’ll send the code. The issue with running plot directly on the simulation outputs is that I have a 6-dim ode. I want to plot only two of the dims as a function of time. I don’t know how to subset out the dimensions of interest.

---

<div class="post-metadata">

**Author:** ![liamfdoherty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liamfdoherty/32/24516_2.png) [@liamfdoherty](https://discourse.julialang.org/u/liamfdoherty)\
**Post date:** [September 16, 2022, 9:31pm UTC](https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387/4 "2022-09-16T21:31:01Z")

</div>

Check [this example](https://diffeq.sciml.ai/stable/basics/plot/#Example) that shows how to use the `vars` keyword to do just that in the case of the Lorenz system.

---

<div class="post-metadata">

**Author:** ![yoshi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoshi/32/38259_2.png) [@yoshi](https://discourse.julialang.org/u/yoshi)\
**Post date:** [September 16, 2022, 9:55pm UTC](https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387/5 "2022-09-16T21:55:13Z")

</div>

Almost, in this example they plot xyzt together. In my example I want something like “xyt” – they have examples of subsetting variables but this is in phase space, not variables vs time.

---

<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:** [September 17, 2022, 12:44am UTC](https://discourse.julialang.org/t/plotting-multiple-ode-trajectories-on-the-same-plot/87387/6 "2022-09-17T00:44:14Z")

</div>

Just use 0 for time.
