From f3dbbf3702f88022f2dcd1bf5b1f7e03991e9862 Mon Sep 17 00:00:00 2001 From: haris organtzidis Date: Fri, 4 Oct 2024 16:43:03 +0300 Subject: [PATCH] add option for static or dynamic gap in `stackplot` (#436) --- ext/MakieExtension.jl | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ext/MakieExtension.jl b/ext/MakieExtension.jl index d26fb753..99d11723 100644 --- a/ext/MakieExtension.jl +++ b/ext/MakieExtension.jl @@ -120,7 +120,7 @@ end @recipe(StackPlot, blox, sol) do scene Theme( - color = :black, + dynamic_gap = false, Axis = ( xlabel = "Time (ms)", ylabel = "Neurons", @@ -146,15 +146,22 @@ function Makie.plot!(p::StackPlot) mx = maximum(V; dims = 1) mn = minimum(V; dims = 1) - offset = 0.0 - for (i, V_neuron) in enumerate(eachcol(V)) - if i == 1 - lines!(p, sol.t, V_neuron; color=p.color[]) - else - offset += abs(mn[i]) * 1.2 - lines!(p, sol.t, offset .+ V_neuron; color=p.color[]) + if p.dynamic_gap[] + offset = 0.0 + for (i, V_neuron) in enumerate(eachcol(V)) + if i == 1 + lines!(p, sol.t, V_neuron) + else + offset += abs(mn[i]) * 1.2 + lines!(p, sol.t, offset .+ V_neuron) + end + offset += abs(mx[i]) * 1.2 + end + else + offset = maximum(mx .- mn) + for (i, V_neuron) in enumerate(eachcol(V)) + lines!(p, sol.t, (i - 1) * offset .+ V_neuron) end - offset += abs(mx[i]) * 1.2 end return p