Skip to content

Commit 70b6d57

Browse files
Use idxs instead of vars for plotting (#252)
1 parent 616b04f commit 70b6d57

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

docs/src/tutorials/dynamical_odes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ u0, du0 = [0.0, 0.1], [0.5, 0.0]
5858
tspan = (0.0, 100.0)
5959
prob = ODEProblem(Hénon_Heiles, [du0; u0], tspan)
6060
sol = solve(prob, EK1());
61-
plot(sol, vars=(3, 4)) # where `vars=(3,4)` is used to plot x agains y
61+
plot(sol, idxs=(3, 4)) # where `idxs=(3,4)` is used to plot x agains y
6262
```
6363

6464
### Solving the second-order ODE directly
@@ -77,7 +77,7 @@ function Hénon_Heiles2(ddu, du, u, p, t)
7777
end
7878
prob2 = SecondOrderODEProblem(Hénon_Heiles2, du0, u0, tspan)
7979
sol2 = solve(prob2, EK1());
80-
plot(sol2, vars=(3, 4))
80+
plot(sol2, idxs=(3, 4))
8181
```
8282

8383
### Benchmark: Solving second order ODEs is _faster_

src/solution_plotting.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33
########################################################################################
44
@recipe function f(
55
sol::AbstractProbODESolution;
6-
vars=nothing,
6+
idxs=nothing,
77
denseplot=sol.dense,
88
plotdensity=1000,
99
tspan=nothing,
1010
ribbon_width=1.96,
11+
vars=nothing,
1112
)
13+
if vars !== nothing
14+
Base.depwarn(
15+
"To maintain consistency with solution indexing, keyword argument vars will be removed in a future version. Please use keyword argument idxs instead.",
16+
:f; force=true)
17+
(idxs !== nothing) &&
18+
error(
19+
"Simultaneously using keywords vars and idxs is not supported. Please only use idxs.",
20+
)
21+
idxs = vars
22+
end
23+
1224
tstart, tend = isnothing(tspan) ? (sol.t[1], sol.t[end]) : tspan
1325
times = denseplot ? range(tstart, tend, length=plotdensity) : sol.t
1426
sol_rvs = denseplot ? sol(times).u : sol.pu
@@ -19,16 +31,16 @@
1931
values = stack(mean.(sol_rvs))
2032
stds = stack(std.(sol_rvs))
2133

22-
if isnothing(vars)
34+
if isnothing(idxs)
2335
ribbon --> ribbon_width * stds
2436
xguide --> "t"
2537
yguide --> "u(t)"
2638
label --> hcat(["u$(i)(t)" for i in 1:length(sol.u[1])]...)
2739
return times, values
2840
else
29-
int_vars = interpret_vars(vars, sol, getsyms(sol))
41+
int_vars = interpret_vars(idxs, sol, getsyms(sol))
3042
varsizes = unique(length.(int_vars))
31-
@assert length(varsizes) == 1 "`vars` argument has an errors"
43+
@assert length(varsizes) == 1 "`idxs` argument has an errors"
3244
ndims = varsizes[1] - 1 # First argument is not about dimensions
3345
if ndims == 2
3446
_x = []

test/solution.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ using ODEProblemLibrary: prob_ode_lotkavolterra
105105
@testset "Plotting" begin
106106
@test_nowarn plot(sol)
107107
@test_nowarn plot(sol, denseplot=false)
108-
@test_nowarn plot(sol, vars=(1, 2))
109-
@test_nowarn plot(sol, vars=(1, 1, 2))
108+
@test_nowarn plot(sol, idxs=(1, 2))
109+
@test_nowarn plot(sol, idxs=(1, 1, 2))
110110
@test_nowarn plot(sol, tspan=prob.tspan)
111111
end
112112

0 commit comments

Comments
 (0)