Skip to content

Commit 13059da

Browse files
authored
add keyword statespace_names in interactive trajecotry (#256)
* add keyword `statespace_names` in interactive trajecotry * fix name of interactive clicker * fix duplicate reference
1 parent e10b737 commit 13059da

5 files changed

Lines changed: 32 additions & 46 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The changelogs of individual sub-packages are self-contained for each package.
1010
# v3.6
1111

1212
- New interactive GUI function: `interactive_2d_clicker`.
13+
- New keyword `statespace_names` for `interactive_trajectory`.
1314

1415
# v3.5
1516

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalSystems"
22
uuid = "61744808-ddfa-5f27-97ff-6e42cc95d634"
33
repo = "https://github.com/JuliaDynamics/DynamicalSystems.jl.git"
4-
version = "3.6.0"
4+
version = "3.6.1"
55

66
[deps]
77
Attractors = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7"

docs/src/visualizations.md

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,32 @@ oddata = interactive_orbitdiagram(ds, p_index, p_min, p_max, i;
240240
ps, us = scaleod(oddata)
241241
```
242242

243-
## Interactive 2D clicker
243+
## Interactive 2D dynamical system
244244

245245
```@docs
246246
interactive_2d_clicker
247247
```
248248

249-
Example:
249+
The `interactive_2d_clicker` function can be used to spin up a GUI
250+
for interactively exploring the state space of a 2D dynamical system.
251+
252+
For example, the following code show how to interactively explore a
253+
[`ProjectedDynamicalSystem`](@ref):
250254

251255
```julia
252256
using GLMakie, DynamicalSystems
253257

258+
# This is the 3D Lorenz model
254259
lorenz = Systems.lorenz()
260+
255261
projection = [1, 2]
256-
complete_state = [12.0]
262+
complete_state = [0.0]
257263
projected_ds = ProjectedDynamicalSystem(lorenz, projection, complete_state)
258264

259-
interactive_2d_clicker(projected_ds; Δt = 0.01, times = 10:100)
265+
interactive_2d_clicker(projected_ds; tfinal = (10.0, 150.0))
260266
```
261267

268+
262269
## Interactive Poincaré Surface of Section
263270

264271
```@raw html
@@ -340,28 +347,3 @@ j = 2 # the dimension of the plane
340347

341348
interactive_poincaresos_scan(trs, j; linekw = (transparency = true,))
342349
```
343-
344-
## Interactive 2D dynamical system
345-
346-
```@docs
347-
interactive_clicker
348-
```
349-
350-
The `interactive_clicker` function can be used to spin up a GUI
351-
for interactively exploring the state space of a 2D dynamical system.
352-
353-
For example, the following code show how to interactively explore a
354-
[`ProjectedDynamicalSystem`](@ref):
355-
356-
```julia
357-
using GLMakie, DynamicalSystems
358-
359-
# This is the 3D Lorenz model
360-
lorenz = Systems.lorenz()
361-
362-
projection = [1, 2]
363-
complete_state = [0.0]
364-
projected_ds = ProjectedDynamicalSystem(lorenz, projection, complete_state)
365-
366-
interactive_clicker(projected_ds; tfinal = (10.0, 150.0))
367-
```

ext/src/interactive_trajectory.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function DynamicalSystems.interactive_trajectory(
2323
axis = NamedTuple(),
2424
lims = nothing,
2525
statespace_axis = true,
26+
statespace_names = state_name.(idxs),
2627
starting_step = 1,
2728
)
2829

@@ -40,7 +41,7 @@ function DynamicalSystems.interactive_trajectory(
4041
statespacelayout = fig[1,1] = GridLayout()
4142
lims = isnothing(lims) ? _traj_lim_estimator(ds, u0s, idxs, [1], Δt)[1] : lims
4243
tailobs, finalpoints = _init_statespace_plot!(statespacelayout, ds, idxs,
43-
lims, pds, colors, plotkwargs, markersize, tail, axis, fade, statespace_axis,
44+
lims, pds, colors, plotkwargs, markersize, tail, axis, fade, statespace_names, statespace_axis,
4445
)
4546
# Set up layouting and add controls
4647
if add_controls # Notice that `run` and `step` are already observables
@@ -130,15 +131,15 @@ vector_idx_observe(ds, u, idxs) = [observe_state(ds, i, u) for i in idxs]
130131
"Create the state space axis and evolution controls. Return the axis."
131132
function _init_statespace_plot!(
132133
layout, ds, idxs, lims, pds, colors, plotkwargs, markersize, tail, axis, fade,
133-
statespace_axis # whether to show the statespace axis
134+
statespace_names, statespace_axis # whether to show the statespace axis
134135
)
135136
tailobs, finalpoints = _init_trajectory_observables(pds, tail)
136137
is3D = length(idxs) == 3
137138
axisposition = statespace_axis ? layout[1,1] : Figure()[1,1]
138-
xlabel = state_name(idxs[1])
139-
ylabel = state_name(idxs[2])
139+
xlabel = statespace_names[1]
140+
ylabel = statespace_names[2]
140141
statespaceax = if is3D
141-
zlabel = state_name(idxs[3])
142+
zlabel = statespace_names[3]
142143
Axis3(axisposition; xlabel, ylabel, zlabel, axis...)
143144
else
144145
Axis(axisposition; xlabel, ylabel, axis...)
@@ -272,16 +273,17 @@ end
272273
# Timeseries extension
273274
###########################################################################################
274275
function DynamicalSystems.interactive_trajectory_timeseries(
275-
ds::DynamicalSystem, fs::Vector, u0s = [current_state(ds)];
276-
linekwargs = isdiscretetime(ds) ? (linewidth = 1,) : (linewidth = 3,),
277-
timeseries_names = [state_name(f) for f in fs],
278-
colors = collect(cgrad(COLORSCHEME, length(u0s); categorical = true)),
279-
timeseries_ylims = nothing,
280-
timelabel = "time", timeunit = 1,
281-
Δt = DynamicalSystems.isdiscretetime(ds) ? 1 : 0.01,
282-
idxs = 1:min(length(u0s[1]), 3),
283-
lims = nothing,
284-
kwargs...)
276+
ds::DynamicalSystem, fs::Vector, u0s = [current_state(ds)];
277+
linekwargs = isdiscretetime(ds) ? (linewidth = 1,) : (linewidth = 3,),
278+
timeseries_names = state_name.(fs),
279+
colors = collect(cgrad(COLORSCHEME, length(u0s); categorical = true)),
280+
timeseries_ylims = nothing,
281+
timelabel = "time", timeunit = 1,
282+
Δt = DynamicalSystems.isdiscretetime(ds) ? 1 : 0.01,
283+
idxs = 1:min(length(u0s[1]), 3),
284+
lims = nothing,
285+
kwargs...
286+
)
285287

286288
# automatic limits
287289
if isnothing(timeseries_ylims) || isnothing(lims)

src/visualizations.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ See also [`interactive_trajectory`](@ref).
9494
9595
- `idxs = 1:min(length(u0s[1]), 3)`: Which variables to plot in a state space trajectory.
9696
Any index that can be given to [`observe_state`](@ref) can be given here.
97+
- `statespace_names = state_name.(idxs)`: Names for the state space axis.
9798
- `statespace_axis = true`: Whether to create and display an axis for the trajectory plot.
9899
- `idxs = 1:min(length(u0s[1]), 3)`: Which variables to plot in a state space trajectory.
99100
Any index that can be given to [`observe_state`](@ref) can be given here.
@@ -108,7 +109,7 @@ See also [`interactive_trajectory`](@ref).
108109
109110
- `linekwargs = NamedTuple()`: Extra keywords propagated to the timeseries plots.
110111
Can also be a vector of named tuples, each one for each unique initial condition.
111-
- `timeseries_names`: A vector of strings with length equal to `fs` giving names to
112+
- `timeseries_names = state_name.(fs)`: A vector of strings with length equal to `fs` giving names to
112113
the y-labels of the timeseries plots.
113114
- `timeseries_ylims`: A vector of 2-tuples for the lower and upper limits of the
114115
y-axis of each timeseries plot. If not given it is deduced automatically similarly to `lims`.

0 commit comments

Comments
 (0)