/
plotting.jl
44 lines (39 loc) · 1.13 KB
/
plotting.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@userplot Scope
"""
scope(sol, varnames)
scope!(sol, varnames)
Plot the variables in `varnames` from an `ODESolution` `sol`.
If `varnames` is a vector, the variables will be plotted against
time on the same axis. If `varnames` is a tuple, the variables
will be plotted against each other.
"""
scope, scope!
@recipe function f(s::Scope)
sol, vars = s.args
t = range(extrema(sol.t)..., length=2000)
signals = get_log(sol, t)
seriestype := :path
xguide --> "t"
if vars isa Symbol
vars = [vars]
end
if vars isa AbstractArray
for var in vars
@series begin
x = getproperty(signals, var)
if x isa AbstractMatrix
sizes = string.(permutedims(1:size(x, 2)))
label --> string(var) * "[:," .* sizes .* "]"
else
label --> "$(string(var))"
end
t, x
end
end
else vars isa Tuple
@series begin
label --> "("*join(string.(vars), ", ")*")"
map(var->getproperty(signals, var), vars)
end
end
end