|
55 | 55 | @recipe function f(sol::DESolution; |
56 | 56 | plot_analytic=false, |
57 | 57 | denseplot = (sol.dense || typeof(sol.prob) <: AbstractDiscreteProblem) && !(typeof(sol) <: AbstractSDESolution), |
58 | | - plotdensity=typeof(sol.prob) <: AbstractDiscreteProblem ? 100*length(sol) : 10*length(sol),vars=nothing) |
| 58 | + plotdensity = sol.tslocation==0 ? (typeof(sol.prob) <: AbstractDiscreteProblem ? 100*length(sol) : 10*length(sol)) : 100*sol.tslocation, |
| 59 | + vars=nothing) |
59 | 60 |
|
60 | 61 | int_vars = interpret_vars(vars,sol) |
61 | 62 |
|
| 63 | + if sol.tslocation == 0 |
| 64 | + end_idx = length(sol) |
| 65 | + else |
| 66 | + end_idx = sol.tslocation |
| 67 | + end |
| 68 | + |
62 | 69 | if denseplot |
63 | 70 | # Generate the points from the plot from dense function |
64 | | - plott = collect(Ranges.linspace(sol.t[1],sol.t[end],plotdensity)) |
| 71 | + plott = collect(Ranges.linspace(sol.t[1],sol.t[end_idx],plotdensity)) |
65 | 72 | plot_timeseries = sol(plott) |
66 | 73 | if plot_analytic |
67 | 74 | plot_analytic_timeseries = [sol.prob.analytic(t,sol.prob.u0) for t in plott] |
68 | 75 | end |
69 | 76 | else |
70 | 77 | # Plot for sparse output: use the timeseries itself |
71 | | - plott = sol.t |
72 | | - plot_timeseries = sol.u |
73 | | - if plot_analytic |
74 | | - plot_analytic_timeseries = sol.u_analytic |
| 78 | + if end_idx == 0 |
| 79 | + plott = sol.t |
| 80 | + plot_timeseries = sol.u |
| 81 | + if plot_analytic |
| 82 | + plot_analytic_timeseries = sol.u_analytic |
| 83 | + end |
| 84 | + else |
| 85 | + plott = sol.t[1:end_idx] |
| 86 | + plot_timeseries = sol.u[1:end_idx] |
| 87 | + if plot_analytic |
| 88 | + plot_analytic_timeseries = sol.u_analytic[1:end_idx] |
| 89 | + end |
75 | 90 | end |
76 | 91 | end |
77 | 92 |
|
|
80 | 95 | @assert length(var) == dims |
81 | 96 | end |
82 | 97 | # Should check that all have the same dims! |
83 | | - plot_vecs,labels = solplot_vecs_and_labels(dims,int_vars,plot_timeseries,plott,sol,plot_analytic) |
| 98 | + plot_vecs,labels = solplot_vecs_and_labels(dims,int_vars,plot_timeseries,plott,sol,plot_analytic,end_idx) |
84 | 99 |
|
85 | 100 | tdir = sign(sol.t[end]-sol.t[1]) |
86 | 101 | xflip --> tdir < 0 |
@@ -222,38 +237,46 @@ function add_analytic_labels!(labels,x,dims,sol) |
222 | 237 | end |
223 | 238 | end |
224 | 239 |
|
225 | | -function u_n(timeseries::AbstractArray, n::Int,sol,plott,plot_timeseries) |
| 240 | +function u_n(timeseries::AbstractArray, n::Int,sol,plott,plot_timeseries,end_idx) |
226 | 241 | # Returns the nth variable from the timeseries, t if n == 0 |
227 | 242 | if n == 0 |
228 | | - plott |
| 243 | + if end_idx == 0 |
| 244 | + return plott |
| 245 | + else |
| 246 | + return plott[1:end_idx] |
| 247 | + end |
229 | 248 | elseif n == 1 && !(typeof(sol[1]) <: AbstractArray) |
230 | | - timeseries |
| 249 | + if end_idx == 0 |
| 250 | + return timeseries |
| 251 | + else |
| 252 | + return timeseries[1:end_idx] |
| 253 | + end |
231 | 254 | else |
232 | 255 | tmp = Vector{eltype(sol[1])}(length(plot_timeseries)) |
233 | 256 | for j in 1:length(plot_timeseries) |
234 | 257 | tmp[j] = plot_timeseries[j][n] |
235 | 258 | end |
236 | | - tmp |
| 259 | + return tmp |
237 | 260 | end |
238 | 261 | end |
239 | 262 |
|
240 | | -function solplot_vecs_and_labels(dims,vars,plot_timeseries,plott,sol,plot_analytic) |
| 263 | +function solplot_vecs_and_labels(dims,vars,plot_timeseries,plott,sol,plot_analytic,end_idx) |
241 | 264 | plot_vecs = [] |
242 | 265 | for i in 1:dims |
243 | 266 | push!(plot_vecs,[]) |
244 | 267 | end |
245 | 268 | labels = String[]# Array{String, 2}(1, length(vars)*(1+plot_analytic)) |
246 | 269 | for x in vars |
247 | 270 | for j in 1:dims |
248 | | - push!(plot_vecs[j], u_n(plot_timeseries, x[j],sol,plott,plot_timeseries)) |
| 271 | + push!(plot_vecs[j], u_n(plot_timeseries, x[j],sol,plott,plot_timeseries,end_idx)) |
249 | 272 | end |
250 | 273 | add_labels!(labels,x,dims,sol) |
251 | 274 | end |
252 | 275 |
|
253 | 276 | if plot_analytic |
254 | 277 | for x in vars |
255 | 278 | for j in 1:dims |
256 | | - push!(plot_vecs[j], u_n(plot_timeseries, x[j],sol,plott,plot_timeseries)) |
| 279 | + push!(plot_vecs[j], u_n(plot_timeseries, x[j],sol,plott,plot_timeseries,end_idx)) |
257 | 280 | end |
258 | 281 | add_analytic_labels!(labels,x,dims,sol) |
259 | 282 | end |
|
0 commit comments