Skip to content

Commit 85f907b

Browse files
Merge pull request #849 from AayushSabharwal/as/plottable-indices
feat: add `plottable_indices`
2 parents c1200b6 + b262f1f commit 85f907b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/solutions/solution_interface.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ function isdenseplot(sol)
201201
sol.interp isa SensitivityInterpolation)
202202
end
203203

204+
"""
205+
$(TYPEDSIGNATURES)
206+
207+
Given the first element in a timeseries solution, return an `AbstractArray` of
208+
indices that can be plotted as continuous variables. This is useful for systems
209+
that store auxiliary variables in the state vector which are not meant to be
210+
used for plotting.
211+
"""
212+
plottable_indices(x::AbstractArray) = 1:length(x)
213+
204214
@recipe function f(sol::AbstractTimeseriesSolution;
205215
plot_analytic = false,
206216
denseplot = isdenseplot(sol),
@@ -225,7 +235,7 @@ end
225235
throw(ArgumentError("No analytic solution was found but `plot_analytic` was set to `true`."))
226236
end
227237

228-
idxs = idxs === nothing ? (1:length(sol.u[1])) : idxs
238+
idxs = idxs === nothing ? plottable_indices(sol.u[1]) : idxs
229239
if !(idxs isa Union{Tuple, AbstractArray})
230240
vars = interpret_vars([idxs], sol)
231241
else

0 commit comments

Comments
 (0)