Skip to content

Commit db52700

Browse files
fix analytical plots
1 parent d6bbac5 commit db52700

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

Diff for: src/solutions/solution_interface.jl

+24-32
Original file line numberDiff line numberDiff line change
@@ -412,34 +412,14 @@ function add_labels!(labels, x, dims, sol, strs)
412412
end
413413

414414
function add_analytic_labels!(labels, x, dims, sol, strs)
415-
lys = []
416-
for j in 3:dims
417-
if x[j] == 0 && dims == 2
418-
push!(lys, "$(getindepsym_defaultt(sol)),")
419-
else
420-
if strs !== nothing
421-
push!(lys, string("True ", strs[x[j]], ","))
422-
else
423-
push!(lys, "True u$(x[j]),")
424-
end
425-
end
426-
end
427-
lys[end] = lys[end][1:(end - 1)] # Take off the last comma
428-
if x[2] == 0
429-
tmp_lab = "$(lys...)($(getindepsym_defaultt(sol)))"
430-
else
431-
if strs !== nothing
432-
tmp = string("True ", strs[x[2]])
433-
tmp_lab = "($tmp,$(lys...))"
434-
else
435-
tmp_lab = "(True u$(x[2]),$(lys...))"
436-
end
437-
end
438-
if x[1] != DEFAULT_PLOT_FUNC
439-
push!(labels, "$(x[1])$(tmp_lab)")
415+
if ((x[2] isa Integer && x[2] == 0) || isequal(x[2],getindepsym_defaultt(sol))) && dims == 2
416+
push!(labels, "True $(strs[end])")
417+
elseif x[1] !== DEFAULT_PLOT_FUNC
418+
push!(labels, "True f($(join(strs, ',')))")
440419
else
441-
push!(labels, tmp_lab)
420+
push!(labels, "True ($(join(strs, ',')))")
442421
end
422+
labels
443423
end
444424

445425
function solplot_vecs_and_labels(dims, vars, plott, sol, plot_analytic,
@@ -486,27 +466,39 @@ function solplot_vecs_and_labels(dims, vars, plott, sol, plot_analytic,
486466
for x in vars
487467
tmp = []
488468
strs = String[]
489-
for j in 2:dims
469+
for j in 2:length(x)
490470
if (x[j] isa Integer && x[j] == 0)
491471
push!(tmp, plott)
492472
push!(strs, "t")
493473
elseif isequal(x[j],getindepsym_defaultt(sol))
494474
push!(tmp, plott)
495475
push!(strs, String(getname(x[j])))
496-
elseif n == 1 && !(sol[:, 1] isa Union{AbstractArray, ArrayPartition})
497-
push!(tmp,timeseries)
498-
push!(strs, String(getname(x[j])))
476+
elseif x[j] == 1 && !(sol[:, 1] isa Union{AbstractArray, ArrayPartition})
477+
push!(tmp,plot_analytic_timeseries)
478+
if !isempty(varsyms) && x[j] isa Integer
479+
push!(strs, String(getname(varsyms[x[j]])))
480+
elseif hasname(x[j])
481+
push!(strs, String(getname(x[j])))
482+
else
483+
push!(strs, "u[$(x[j])]")
484+
end
499485
else
500486
_tmp = Vector{eltype(sol[1])}(undef, length(plot_timeseries))
501487
for j in 1:length(plot_timeseries)
502488
_tmp[j] = plot_timeseries[j][n]
503489
end
504490
push!(tmp,_tmp)
505-
push!(strs, String(getname(x[j])))
491+
if !isempty(varsyms) && x[j] isa Integer
492+
push!(strs, String(getname(varsyms[x[j]])))
493+
elseif hasname(x[j])
494+
push!(strs, String(getname(x[j])))
495+
else
496+
push!(strs, "u[$(x[j])]")
497+
end
506498
end
507499
end
508500
f = x[1]
509-
tmp = f.(tmp...)
501+
tmp = map(f,tmp...)
510502
tmp = tuple((getindex.(tmp, i) for i in eachindex(tmp[1]))...)
511503
for i in eachindex(tmp)
512504
push!(plot_vecs[i], tmp[i])

Diff for: test/solution_interface.jl

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ end
1414
push!(sol.u, ode.u0)
1515
end
1616

17-
syms = SciMLBase.interpret_vars(nothing, sol, SciMLBase.getsyms(sol))
18-
int_vars = SciMLBase.interpret_vars(nothing, sol, syms) # nothing = idxs
17+
int_vars = SciMLBase.interpret_vars(nothing, sol) # nothing = idxs
1918
plot_vecs, labels = SciMLBase.diffeq_to_arrays(sol,
2019
true, # plot_analytic
2120
true, # denseplot
2221
10, # plotdensity
2322
ode.tspan,
24-
0.1, # axis_safety
25-
nothing, # idxs
2623
int_vars,
27-
:identity, # tscale
28-
nothing) # strs
24+
:identity) # tscale
2925
@test plot_vecs[2][:, 2] @. exp(-plot_vecs[1][:, 2])
3026
end
3127

0 commit comments

Comments
 (0)