Skip to content

Trajectory Highlighter

Docstrings

#InteractiveChaos.trajectory_highlighterFunction.

trajectory_highlighter(datasets, vals; kwargs...)

Open an interactive application for highlighting specific datasets and properties of these datasets. datasets is a vector of anything from DynamicalSystems.jl that supports plot_dataset (currently Dataset or Matrix). Each dataset corresponds to a specific value from vals (a Vector{<:Real}). The value of vals gives each dataset a specific color based on a colormap.

The application is composed of two scenes: the left scene plots the datasets, while the right scene plots the histogram of the vals. The function returns the two scenes data_scene, hist_scene.

Interaction

Clicking on a bin of the histogram plot will "highlight" all data whose value belongs in that bin. Here highlighting actually means "hidding" (i.e. reducing their alpha value) all other data besides the ones you want to highlight. Clicking on empty space on the histogram plot will reset highlighting.

Clicking on a plotted series in the left window will highlight this series as well as the histogram bin that contains its value. Clicking on empty space will reset the highlighting.

Keyword Arguments

  • nbins = 10, closed = :left : used in producing the histogram.
  • α = 0.05 : the alpha value of the hidden data.
  • hα = 0.2 : the alpha value of the hidden histogram bins.
  • cmap = :viridis : the colormap used.
  • hname = "value" : name for the histogram axis.
  • kwargs... : Anything else is propagated to plot_dataset.

Function Video

using InteractiveChaos, Makie

ds = Systems.henonheiles()

# Grid of initial conditions at given energy:
energy(x,y,px,py) = 0.5(px^2 + py^2) + potential(x,y)
potential(x, y) = 0.5(x^2 + y^2) + (x^2*y - (y^3)/3)
function generate_ics(E, n)
    ys = range(-0.4, stop = 1.0, length = n)
    pys = range(-0.5, stop = 0.5, length = n)
    ics = Vector{Vector{Float64}}()
    for y in ys
        V = potential(0.0, y)
        V  E && continue
        for py in pys
            Ky = 0.5*(py^2)
            Ky + V  E && continue
            px = sqrt(2(E - V - Ky))
            ic = [0.0, y, px, py]
            push!(ics, [0.0, y, px, py])
        end
    end
    return ics
end

density = 15
tfinal = 2000.0
tgali = 1000.0
E = 0.13
ics = generate_ics(E, density)

tinteg = tangent_integrator(ds, 4)

regularity = Float64[]; psos = Dataset{2, Float64}[]
trs = Dataset{3, Float64}[]
@time for u in ics
    # compute gali (using advanced usage)
    reinit!(tinteg, u, orthonormal(4,4))
    push!(regularity, gali(tinteg, tgali, 1, 1e-12)[2][end]/tgali)
    push!(psos, poincaresos(ds, (1, 0.0), 2000.0; u0 = u, idxs = [2, 4]))
    tr = trajectory(ds, 200.0, u)[:, [1, 2, 4]]
    push!(trs, tr)
end

# %%
# 2D version:
trajectory_highlighter(psos, regularity; α = 0.05, hname = "regularity")
# 3D version:
trajectory_highlighter(trs[1:10:end], regularity[1:10:end];
nbins = 10, α = 0.05, linewidth = 4.0, hname = "regularity")

2D Version:

3D Version: