Skip to content

Commit

Permalink
Merge pull request #849 from AayushSabharwal/as/plottable-indices
Browse files Browse the repository at this point in the history
feat: add `plottable_indices`
  • Loading branch information
ChrisRackauckas authored Nov 7, 2024
2 parents c1200b6 + b262f1f commit 85f907b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/solutions/solution_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ function isdenseplot(sol)
sol.interp isa SensitivityInterpolation)
end

"""
$(TYPEDSIGNATURES)
Given the first element in a timeseries solution, return an `AbstractArray` of
indices that can be plotted as continuous variables. This is useful for systems
that store auxiliary variables in the state vector which are not meant to be
used for plotting.
"""
plottable_indices(x::AbstractArray) = 1:length(x)

@recipe function f(sol::AbstractTimeseriesSolution;
plot_analytic = false,
denseplot = isdenseplot(sol),
Expand All @@ -225,7 +235,7 @@ end
throw(ArgumentError("No analytic solution was found but `plot_analytic` was set to `true`."))
end

idxs = idxs === nothing ? (1:length(sol.u[1])) : idxs
idxs = idxs === nothing ? plottable_indices(sol.u[1]) : idxs
if !(idxs isa Union{Tuple, AbstractArray})
vars = interpret_vars([idxs], sol)
else
Expand Down

0 comments on commit 85f907b

Please sign in to comment.