From 6f64feebdd284e926073092e743395fc7dd46773 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 12 Sep 2024 13:05:41 +0000 Subject: [PATCH 01/67] new example_data with splines --- docs/example_data.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/example_data.jl b/docs/example_data.jl index 082bae000..4f114f74e 100644 --- a/docs/example_data.jl +++ b/docs/example_data.jl @@ -19,6 +19,7 @@ Creates example data. Currently, 7 datasets are available. function example_data(example = "TopoPlots.jl") if example == "UnfoldLinearModel" + # load and generate a simulated Unfold Design data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) data = reshape(data, (1, size(data)...)) @@ -32,6 +33,23 @@ function example_data(example = "TopoPlots.jl") data; solver = se_solver, ) + elseif example == "UnfoldLinearModelwithSpline" + # load and generate a simulated Unfold Design + data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) + data = reshape(data, (1, size(data)...)) + evts.continuous2 .= + log10.(6 .+ rand(MersenneTwister(1), length(evts.continuous))) .^ 2 + f = @formula 0 ~ 1 + condition + spl(continuous, 4) + spl(continuous2, 4) + # generate ModelStruct + se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) + return fit( + UnfoldModel, + [Any => (f, range(0, length = size(data, 2), step = 1 / 100))], + evts, + data; + solver = se_solver, + ) + elseif example == "UnfoldLinearModelMultiChannel" # load and generate a simulated Unfold Design cAll = DataFrame() From b46dffdfeb41cb07203ca88f5b057087ee9d97fb Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 12 Sep 2024 16:33:09 +0000 Subject: [PATCH 02/67] categorical colors depricated, issues 235, 231 --- src/plot_erp.jl | 45 ++++++++++--------------- test/test_complexplots.jl | 22 ++---------- test/test_erp.jl | 44 ++++++++---------------- test/test_erp_effects.jl | 70 ++++++++++++++++----------------------- 4 files changed, 63 insertions(+), 118 deletions(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 63bcfc17c..97ed3f7ee 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -55,13 +55,16 @@ function plot_erp!( plot_data::Union{DataFrame,AbstractMatrix,AbstractVector{<:Number}}; positions = nothing, labels = nothing, - categorical_color = true, - categorical_group = true, + categorical_color = nothing, + categorical_group = nothing, stderror = false, # XXX if it exists, should be plotted significance = nothing, mapping = (;), kwargs..., ) + if !(isnothing(categorical_color) && isnothing(categorical_group)) + @warn "categorical_color and categorical_group have been deprecated. To switch to categorical colors, please use `mapping(...,color=:mycolorcolum=>nonnumeric)`. `group` is now automatically cast to nonnumeric." + end config = PlotConfig(:erp) config_kwargs!(config; mapping, kwargs...) plot_data = deepcopy(plot_data) @@ -90,34 +93,24 @@ function plot_erp!( plot_data[!, :se_low] = plot_data[:, config.mapping.y] .- plot_data.stderror plot_data[!, :se_high] = plot_data[:, config.mapping.y] .+ plot_data.stderror end - # Categorical mapping - # convert color column into string to prevent wrong grouping - if categorical_color && (:color ∈ keys(config.mapping)) - config.mapping = - merge(config.mapping, (; color = config.mapping.color => nonnumeric)) - end - # converts group column into string - if categorical_group && (:group ∈ keys(config.mapping)) - config.mapping = - merge(config.mapping, (; group = config.mapping.group => nonnumeric)) - end + # automatically convert col & group to nonnumeric if ( - :col ∈ keys(config.mapping) && + :col ∈ keys(config.mapping) && !isa(config.mapping.col, Pair) && typeof(plot_data[:, config.mapping.col]) <: AbstractVector{<:Number} ) config.mapping = merge(config.mapping, (; col = config.mapping.col => nonnumeric)) end - mapp = AlgebraOfGraphics.mapping() - - if (:color ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.color) + if ( + :group ∈ keys(config.mapping) && !isa(config.mapping.group, Pair) && + typeof(plot_data[:, config.mapping.group]) <: AbstractVector{<:Number} + ) + config.mapping = + merge(config.mapping, (; group = config.mapping.group => nonnumeric)) end - if (:group ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.group) - end + mapp = AlgebraOfGraphics.mapping() # remove x / y mapping_others = deleteKeys(config.mapping, [:x, :y, :positions, :lables]) @@ -140,18 +133,16 @@ function plot_erp!( plot_equation = basic * mapp - f_grid = f[1, 1:4] - - # draw a standart ERP lineplot + f_grid = f[1, 1] = GridLayout() drawing = draw!(f_grid, plot_equation; axis = config.axis) + if config.layout.show_legend == true config_kwargs!(config; mapping, layout = (; show_legend = false)) if config.layout.use_legend == true - legend!(f[:, 5], drawing; config.legend...) + legend!(f_grid[:, end+1], drawing; config.legend...) end if config.layout.use_colorbar == true - N = config.layout.use_legend == false ? 5 : 6 - colorbar!(f[:, N], drawing; config.colorbar...) + colorbar!(f_grid[:, end+1], drawing; config.colorbar...) end end apply_layout_settings!(config; fig = f, ax = drawing, drawing = drawing) diff --git a/test/test_complexplots.jl b/test/test_complexplots.jl index 82ca44a53..46492ce81 100644 --- a/test/test_complexplots.jl +++ b/test/test_complexplots.jl @@ -117,14 +117,7 @@ end # if coefname not specified, line should be black coefname = ["(Intercept)", "category: face"], ) - plot_erp!( - f[1, 1], - results, - categorical_color = false, - categorical_group = false, - significance = pvals, - stderror = true, - ) + plot_erp!(f[1, 1], results, significance = pvals, stderror = true) plot_butterfly!(f[1, 2], d_topo, positions = positions) plot_topoplot!(f[2, 1], data[:, 150, 1]; positions = positions) @@ -181,14 +174,7 @@ end # if coefname not specified, line should be black coefname = ["(Intercept)", "category: face"], ) - plot_erp!( - f[2, 1:2], - results, - categorical_color = false, - categorical_group = false, - significance = pvals, - stderror = true, - ) + plot_erp!(f[2, 1:2], results, significance = pvals, stderror = true) plot_designmatrix!(f[2, 3], designmatrix(uf)) @@ -206,9 +192,7 @@ end plot_erp!( f[2, 4:5], res_effects; - categorical_color = false, - categorical_group = true, - mapping = (; y = :yhat, color = :continuous, group = :continuous), + mapping = (; y = :yhat, color = :continuous, group = :continuous => nonnumeric), layout = (; show_legend = true), ) diff --git a/test/test_erp.jl b/test/test_erp.jl index 5f19b9bf8..e43c0faab 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -18,6 +18,14 @@ end plot_erp(dat[1, :, 1]) end +@testset "ERP plot: rename xlabel" begin + plot_erp(results; axis = (; xlabel = "test")) +end + +@testset "ERP plot: xlabelvisible" begin + plot_erp(results; axis = (; xlabelvisible = false, xticklabelsvisible = false)) +end + @testset "ERP plot: Array data with times vector" begin times = range(0, step = 100, length = size(dat, 2)) plot_erp(times, dat[1, :, 1], axis = (; xtickformat = "{:d}")) @@ -42,14 +50,15 @@ end @testset "ERP plot: with and withour error ribbons" begin results = coeftable(m) - f = Figure() results.coefname = - replace(results.coefname, "condition: face" => "face", "(Intercept)" => "car") + replace(results.coefname, "condition: face" => "face", "(Intercept)" => "car") results = filter(row -> row.coefname != "continuous", results) + + f = Figure() plot_erp!( f[1, 1], results; - axis = (title = "Bad example", titlegap = 12), + axis = (; title = "Bad example", titlegap = 12), :stderror => false, mapping = (; color = :coefname => "Conditions"), ) @@ -81,14 +90,7 @@ end # if coefname not specified, line should be black coefname = ["(Intercept)", "category: face"], ) - plot_erp!( - ga, - results; - categorical_color = false, - categorical_group = false, - significance = pvals, - stderror = true, - ) + plot_erp!(ga, results; significance = pvals, stderror = true) f end @@ -107,24 +109,6 @@ end plot_erp(results7, mapping = (; col = :channel, group = :channel)) end - -@testset "ERP plot: with colorbar and legend" begin - plot_erp( - res_effects2; - mapping = (; color = :continuous, linestyle = :condition, group = :continuous), - categorical_color = false, - ) -end - -#= @testset "ERP plot: with colorbar and legend 2" begin - plot_erp( - res_effects2; - mapping = (; color = :continuous, group = :continuous), - categorical_color = false, - categorical_group = false, - ) -end =# - @testset "ERP plot: rename legend" begin f = Figure() results = coeftable(m) @@ -132,7 +116,7 @@ end =# replace(results.coefname, "condition: face" => "face", "(Intercept)" => "car") results = filter(row -> row.coefname != "continuous", results) plot_erp!( - f[1, 1], + f, results; axis = (title = "Bad example", titlegap = 12), :stderror => false, diff --git a/test/test_erp_effects.jl b/test/test_erp_effects.jl index 59eb817eb..dc8b2e17d 100644 --- a/test/test_erp_effects.jl +++ b/test/test_erp_effects.jl @@ -5,62 +5,48 @@ m = example_data("UnfoldLinearModel") res_effects = effects(Dict(:continuous => -5:0.5:5), m) res_effects2 = effects(Dict(:condition => ["car", "face"], :continuous => -5:5), m) -@testset "Effect plot" begin #where is legend here?? - plot_erp( - res_effects; - mapping = (; y = :yhat, color = :continuous, group = :continuous), - legend = (; nbanks = 2), - categorical_color = false, - categorical_group = true, - ) +@testset "Effect plot" begin + plot_erp(res_effects; mapping = (; y = :yhat, color = :continuous, group = :continuous)) end -@testset "Effect plot: faceted" begin #bug +@testset "Effect plot: faceted" begin res_effects = effects(Dict(:continuous => -5:0.5:5), m) res_effects.channel = push!(repeat(["1", "2"], 472), "1") - plot_erp(res_effects; mapping = (; y = :yhat, color = :continuous, col = :channel)) + plot_erp( + res_effects; + mapping = (; y = :yhat, color = :continuous => nonnumeric, col = :channel), + legend = (; nbanks = 2), + ) end @testset "Effect plot: faceted channels" begin #bug res_effects = effects(Dict(:continuous => -5:0.5:5), m) res_effects.channel = push!(repeat(["1", "2"], 472), "1") - #res_effects.channel = float.(push!(repeat([1, 2], 472), 1)) - plot_erp(res_effects; mapping = (; y = :yhat, group = :channel, col = :channel)) -end - -@testset "Effect plot: no colorbar and legend" begin plot_erp( - res_effects2; - mapping = (; color = :continuous, linestyle = :condition, group = :continuous), - layout = (; show_legend = true, use_legend = false, use_colorbar = false), - categorical_color = false, + res_effects; + mapping = (; + y = :yhat, + color = :continuous => nonnumeric, + group = :channel, + col = :channel => nonnumeric, + ), + legend = (; nbanks = 2), ) end -@testset "Effect plot: no colorbar" begin +@testset "Effect plot: no colorbar and yes legend" begin plot_erp( res_effects2; mapping = (; color = :continuous, linestyle = :condition, group = :continuous), layout = (; use_legend = true, use_colorbar = false), - categorical_color = false, ) end -@testset "Effect plot: no legend" begin +@testset "Effect plot: yes colorbar and no legend" begin plot_erp( res_effects2; mapping = (; color = :continuous, linestyle = :condition, group = :continuous), layout = (; use_legend = false, use_colorbar = true), - categorical_color = false, - ) -end - -@testset "Effect plot: no colorbar and no legend" begin - plot_erp( - res_effects2; - mapping = (; color = :continuous, linestyle = :condition, group = :continuous), - layout = (; use_legend = false, use_colorbar = false), - categorical_color = false, ) end @@ -69,26 +55,22 @@ end res_effects2; mapping = (; color = :continuous, linestyle = :condition, group = :continuous), layout = (; use_legend = true, use_colorbar = true), - categorical_color = false, ) end - -@testset "Effect plot: should be no gap instead of legend" begin +@testset "Effect plot: no colorbar and no legend" begin plot_erp( res_effects2; - mapping = (; color = :continuous, group = :continuous), - categorical_color = false, + mapping = (; color = :continuous, linestyle = :condition, group = :continuous), + layout = (; use_legend = false, use_colorbar = false), ) end - @testset "Effect plot: move legend" begin plot_erp( res_effects2; mapping = (; color = :continuous, linestyle = :condition, group = :continuous), - legend = (; valign = :bottom, halign = :right, tellwidth = false), - categorical_color = false, + legend = (; valign = :bottom, halign = :right), axis = ( title = "Marginal effects", titlegap = 12, @@ -104,14 +86,18 @@ end @testset "Effect plot: xlabelvisible is not working" begin eff_same = effects(Dict(:condition => ["car", "face"], :duration => 200), m) + + plot_erp(results; axis = (; xlabelvisible = false, xticklabelsvisible = false)) plot_erp( - res_effects2; - mapping = (; col = :eventname),#, color = :condition), why it doesn't work??? + eff_same; + mapping = (; col = :condition, color = :time), axis = (; + xlabel = "test", titlevisible = false, xlabelvisible = false, ylabelvisible = false, yticklabelsvisible = false, + xticklabelsvisible = false, ), ) end From 5abd763fb36e965cc976370d6b8fbfdfae1466bc Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 12 Sep 2024 16:34:28 +0000 Subject: [PATCH 03/67] remnants --- src/plot_erp.jl | 4 ---- src/plotconfig.jl | 1 - 2 files changed, 5 deletions(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 97ed3f7ee..e4caf8764 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -19,10 +19,6 @@ Plot an ERP plot. ## Keyword arguments (kwargs) -- `categorical_color::Bool = true`\\ - Treat `:color` as categorical variable in case of numeric `:color` column. -- `categorical_group::Bool = true`\\ - Treat `:group` as categorical variable in case of numeric `:group` column. - `stderror::Bool = false`\\ Add an error ribbon, with lower and upper limits based on the `:stderror` column. - `significance::DataFrame = nothing`\\ diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 7d895a44f..a7e0342d4 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -226,7 +226,6 @@ function PlotConfig(T::Val{:erp}) )), ), legend = (; - tellwidth = false, halign = :right, valign = :center, framevisible = false, From 44a9da5aecbc88a6b790959a1c2c51537632ad9d Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:35:43 +0000 Subject: [PATCH 04/67] Update src/plot_erp.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/plot_erp.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index e4caf8764..ff306b5b0 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -92,7 +92,8 @@ function plot_erp!( # automatically convert col & group to nonnumeric if ( - :col ∈ keys(config.mapping) && !isa(config.mapping.col, Pair) && + :col ∈ keys(config.mapping) && + !isa(config.mapping.col, Pair) && typeof(plot_data[:, config.mapping.col]) <: AbstractVector{<:Number} ) config.mapping = merge(config.mapping, (; col = config.mapping.col => nonnumeric)) From 9e409601deb4c35f6e458e43d772384616a2544c Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:35:58 +0000 Subject: [PATCH 05/67] Update test/test_erp.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/test_erp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_erp.jl b/test/test_erp.jl index e43c0faab..c918a5c50 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -51,7 +51,7 @@ end @testset "ERP plot: with and withour error ribbons" begin results = coeftable(m) results.coefname = - replace(results.coefname, "condition: face" => "face", "(Intercept)" => "car") + replace(results.coefname, "condition: face" => "face", "(Intercept)" => "car") results = filter(row -> row.coefname != "continuous", results) f = Figure() From 80e88eac5be9467fa111b9c31554ef9fef4c1640 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:36:06 +0000 Subject: [PATCH 06/67] Update src/plot_erp.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/plot_erp.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index ff306b5b0..6a608927e 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -100,7 +100,8 @@ function plot_erp!( end if ( - :group ∈ keys(config.mapping) && !isa(config.mapping.group, Pair) && + :group ∈ keys(config.mapping) && + !isa(config.mapping.group, Pair) && typeof(plot_data[:, config.mapping.group]) <: AbstractVector{<:Number} ) config.mapping = From 43b0cabfe6ba1e5477b2541c7769f5afa4810248 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 12 Sep 2024 17:06:32 +0000 Subject: [PATCH 07/67] removing remnants from docs --- docs/literate/how_to/mult_vis_in_fig.jl | 5 +---- docs/literate/tutorials/erp.jl | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/literate/how_to/mult_vis_in_fig.jl b/docs/literate/how_to/mult_vis_in_fig.jl index 079339dc0..ba916f718 100644 --- a/docs/literate/how_to/mult_vis_in_fig.jl +++ b/docs/literate/how_to/mult_vis_in_fig.jl @@ -72,8 +72,6 @@ pvals = DataFrame( plot_erp!( f[2, 1:2], results, - categorical_color = false, - categorical_group = false, significance = pvals, stderror = true, ) @@ -94,9 +92,8 @@ res_effects = effects(Dict(:continuous => -5:0.5:5), uf_deconv) plot_erp!( f[2, 4:5], res_effects; - categorical_color = false, categorical_group = true, - mapping = (; y = :yhat, color = :continuous, group = :continuous), + mapping = (; y = :yhat, color = :continuous, group = :continuous => nonnumeric), legend = (; nbanks = 2), layout = (; show_legend = true, legend_position = :right), ) diff --git a/docs/literate/tutorials/erp.jl b/docs/literate/tutorials/erp.jl index 9f3f8a9ea..b063821dc 100644 --- a/docs/literate/tutorials/erp.jl +++ b/docs/literate/tutorials/erp.jl @@ -54,8 +54,6 @@ plot_erp( res_effects; mapping = (; y = :yhat, color = :continuous, group = :continuous), layout = (; show_legend = false), - categorical_color = false, # perceives color (here: continuous) as contionus - categorical_group = true, # separates lines, if `false` all lines will be connected ) # ## Significance lines From c07da9c61cf4c0ea3b224cc567ffc45729f4743e Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 12 Sep 2024 17:25:39 +0000 Subject: [PATCH 08/67] tiny --- docs/literate/how_to/mult_vis_in_fig.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/docs/literate/how_to/mult_vis_in_fig.jl b/docs/literate/how_to/mult_vis_in_fig.jl index ba916f718..b28782598 100644 --- a/docs/literate/how_to/mult_vis_in_fig.jl +++ b/docs/literate/how_to/mult_vis_in_fig.jl @@ -69,12 +69,7 @@ pvals = DataFrame( to = [0.2, 0.5], # if coefname not specified, line should be black coefname = ["(Intercept)", "category: face"], ) -plot_erp!( - f[2, 1:2], - results, - significance = pvals, - stderror = true, -) +plot_erp!(f[2, 1:2], results, significance = pvals, stderror = true) plot_designmatrix!(f[2, 3], designmatrix(uf)) @@ -92,7 +87,6 @@ res_effects = effects(Dict(:continuous => -5:0.5:5), uf_deconv) plot_erp!( f[2, 4:5], res_effects; - categorical_group = true, mapping = (; y = :yhat, color = :continuous, group = :continuous => nonnumeric), legend = (; nbanks = 2), layout = (; show_legend = true, legend_position = :right), From 5642eaf60360bae5fa331ad8b34e38cd8b818514 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 13 Sep 2024 09:15:31 +0000 Subject: [PATCH 09/67] better p_vals --- docs/literate/tutorials/erp.jl | 4 ++-- test/test_erp.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/literate/tutorials/erp.jl b/docs/literate/tutorials/erp.jl index b063821dc..3e2a97ebd 100644 --- a/docs/literate/tutorials/erp.jl +++ b/docs/literate/tutorials/erp.jl @@ -66,8 +66,8 @@ plot_erp( m = example_data("UnfoldLinearModel") results = coeftable(m) significancevalues = DataFrame( - from = [0.1, 0.3], - to = [0.5, 0.7], + from = [0.01, 0.2], + to = [0.3, 0.4], coefname = ["(Intercept)", "condition: face"], # if coefname not specified, line should be black ) plot_erp(results; :significance => significancevalues) diff --git a/test/test_erp.jl b/test/test_erp.jl index c918a5c50..cd0bacb93 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -96,8 +96,8 @@ end @testset "ERP plot with significance" begin pvals = DataFrame( - from = [0.1, 0.3], - to = [0.5, 0.7], + from = [0.01, 0.2], + to = [0.3, 0.4], coefname = ["(Intercept)", "condition: face"], # if coefname not specified, line should be black ) plot_erp(results; :significance => pvals) From 0923c3f5405fe23d11b2efc0bf930aa8a8a642e4 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 13 Sep 2024 10:12:52 +0000 Subject: [PATCH 10/67] first working splie plot --- Project.toml | 1 + docs/src/index.md | 2 +- src/UnfoldMakie.jl | 3 +++ src/plot_erp.jl | 4 +++- src/plot_parallelcoordinates.jl | 2 -- src/plot_spline_config.jl | 34 +++++++++++++++++++++++++++++++++ test/Project.toml | 1 + test/runtests.jl | 4 ++++ test/test_complexplots.jl | 1 - test/test_splines.jl | 25 ++++++++++++++++++++++++ 10 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 src/plot_spline_config.jl create mode 100644 test/test_splines.jl diff --git a/Project.toml b/Project.toml index d27ac0ac6..cb5cb205e 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.5.7" [deps] AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67" +BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a" CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" diff --git a/docs/src/index.md b/docs/src/index.md index 2b5c9834b..3ba1b8939 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -17,6 +17,6 @@ The package is primarily based on [Unfold.jl](https://github.com/unfoldtoolbox/u - **Many usage examples** You can find many user-friendly examples of how to use and adapt the plots in this documentation. - **Scientific colormaps by default** -According to our study [(Mikheev, 2024)](https://apertureneuro.org/article/116386-the-art-of-brainwaves-a-survey-on-event-related-potential-visualization-practices), 40% of EEG researchers do not know about the issue of scientific color maps. By default, we use `Reverse(:RdBu)` (based on [colorbrewer](https://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3)) and `Roma` (based on [Sceintific Colormaps](https://www.fabiocrameri.ch/colourmaps/) by Fabio Crameri) as default color maps. +According to our study [(Mikheev, 2024)](https://apertureneuro.org/article/116386-the-art-of-brainwaves-a-survey-on-event-related-potential-visualization-practices), 40% of EEG researchers do not know about the issue of scientific color maps. As default color maps we use `Reverse(:RdBu)` (based on [colorbrewer](https://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3)) and `Roma` (based on [Sceintific Colormaps](https://www.fabiocrameri.ch/colourmaps/) by Fabio Crameri). - **Interactivity** Several plots make use of `Observables.jl` which allows fast updating of the underlying data. Several plots already have predefined interactive features, e.g. you can click on labels to enable / disable them. See `plot_topoplotseries` and `plot_erpimage` for examples. diff --git a/src/UnfoldMakie.jl b/src/UnfoldMakie.jl index 596419461..c6b1c8aa5 100644 --- a/src/UnfoldMakie.jl +++ b/src/UnfoldMakie.jl @@ -55,6 +55,7 @@ include("plot_topoplotseries.jl") include("plot_erp.jl") include("plot_butterfly.jl") include("plot_designmatrix.jl") +include("plot_spline_config.jl") include("plot_topoplot.jl") include("plot_erpimage.jl") include("plot_parallelcoordinates.jl") @@ -71,6 +72,8 @@ export PlotConfig export plot_designmatrix export plot_designmatrix! +export plot_spline_config +export plot_spline_config! export plot_erp export plot_erp! export plot_erpimage diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 6a608927e..84fbd6f58 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -59,7 +59,9 @@ function plot_erp!( kwargs..., ) if !(isnothing(categorical_color) && isnothing(categorical_group)) - @warn "categorical_color and categorical_group have been deprecated. To switch to categorical colors, please use `mapping(...,color=:mycolorcolum=>nonnumeric)`. `group` is now automatically cast to nonnumeric." + @warn "categorical_color and categorical_group have been deprecated. + To switch to categorical colors, please use `mapping(..., color = :mycolorcolum => nonnumeric)`. + `group` is now automatically cast to nonnumeric." end config = PlotConfig(:erp) config_kwargs!(config; mapping, kwargs...) diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index 9192148c1..c7064b47a 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -165,7 +165,6 @@ function parallelcoordinates( minlist = minimum(plotdata) maxlist = maximum(plotdata) end - # @debug plotdata # edge bending / bundling if !bend @@ -345,7 +344,6 @@ Used to inject extrema ticks and round them if necessary. struct PCPTicks end function Makie.get_ticks(ticks::PCPTicks, scale, formatter, vmin, vmax) - #@debug "get_ticks custom",vmin,vmax tickvalues = Makie.get_tickvalues(Makie.WilkinsonTicks(5), scale, vmin, vmax) ticklabels_without = Makie.get_ticklabels(formatter, tickvalues) diff --git a/src/plot_spline_config.jl b/src/plot_spline_config.jl new file mode 100644 index 000000000..daf8d69af --- /dev/null +++ b/src/plot_spline_config.jl @@ -0,0 +1,34 @@ +using BSplineKit, Unfold +""" + plot_spline_config(m::UnfoldModel; kwargs...) + +**Return Value:** `Figure` with spline configuration for basis functions. +""" +plot_spline_config(m::UnfoldModel; kwargs...) = plot_spline_config(Figure(), m; kwargs...) + +function plot_spline_config( + f::Union{GridPosition,GridLayout,Figure}, + m::UnfoldModel; + kwargs..., +) + splFunction = Base.get_extension(Unfold, :UnfoldBSplineKitExt).splFunction + spl_ix = findall(isa.(Unfold.formulas(m)[1].rhs.terms, Unfold.AbstractSplineTerm)) + spline_terms = Unfold.formulas(m)[1].rhs.terms[spl_ix[2]] + + x_range = + range(spline_terms.breakpoints[1], stop = spline_terms.breakpoints[2], length = 100) + basis_set = splFunction(x_range, spline_terms) + + a1 = Axis(f[1, 1]) + series!(x_range, basis_set') + + a2 = Axis(f[2, 1]) + density!( + Unfold.events(designmatrix(m))[1][:, spline_terms.term.sym]; + color = :transparent, + strokecolor = :black, + strokewidth = 1, + ) + linkxaxes!(a1, a2) + f +end diff --git a/test/Project.toml b/test/Project.toml index 51872b03f..ff865372a 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,5 +1,6 @@ [deps] AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67" +BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a" CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" diff --git a/test/runtests.jl b/test/runtests.jl index 976f86f0c..ceafcb803 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -54,6 +54,10 @@ end include("test_dm.jl") end +@testset "Spline plots" begin + include("test_splines.jl") +end + @testset "Complex plots" begin include("test_complexplots.jl") end diff --git a/test/test_complexplots.jl b/test/test_complexplots.jl index 46492ce81..40907b2f6 100644 --- a/test/test_complexplots.jl +++ b/test/test_complexplots.jl @@ -110,7 +110,6 @@ end uf_5chan = example_data("UnfoldLinearModelMultiChannel") d_singletrial, _ = UnfoldSim.predef_eeg(; return_epoched = true) - pvals = DataFrame( from = [0.1, 0.15], to = [0.2, 0.5], diff --git a/test/test_splines.jl b/test/test_splines.jl new file mode 100644 index 000000000..6612b26ca --- /dev/null +++ b/test/test_splines.jl @@ -0,0 +1,25 @@ +using BSplineKit, Unfold +m = example_data("UnfoldLinearModelwithSpline") + +@testset "Spline plot: basic" begin + plot_spline_config(m) +end + +#= rng = MersenneTwister(2) # make repeatable +n = 20 # datapoints +evts = DataFrame(:x => rand(rng, n)) +signal = -(3 * (evts.x .- 0.5)) .^ 2 .+ 0.5 .* rand(rng, n) +signal = reshape(signal, length(signal), 1, 1) +signal = permutedims(signal, [3, 2, 1]) +design_spl10 = [Any => (@formula(0 ~ 1 + spl(x, 10)), [0])]; + +uf_spl10 = fit(UnfoldModel, design_spl10, evts, signal); +term_spl = Unfold.formulas(uf_spl10)[1].rhs.terms[2] + +basisSet = splFunction(0.0:0.01:1, term_spl) + +basisSet = disallowmissing(basisSet[.!any(ismissing.(basisSet), dims = 2)[:, 1], :]) # remove missings +ax = Axis(Figure()[1, 1]) +[lines!(ax, basisSet[:, k]) for k = 1:size(basisSet, 2)] +current_figure() + =# From b8a9147dc768e74480ea5b14231e110a479eb8e7 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 13 Sep 2024 10:35:33 +0000 Subject: [PATCH 11/67] bug --- src/plot_parallelcoordinates.jl | 2 +- src/plotconfig.jl | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index c7064b47a..e48a4563c 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -174,7 +174,7 @@ function parallelcoordinates( x_plotdata = range(1, x_pos[end], step = 0.05) plotdata_int = Array{Float64}(undef, length(x_plotdata), size(plotdata, 2)) for k = 1:size(plotdata, 2) - itp = interpolate(plotdata[:, k], BSpline(Cubic(Interpolations.Line(OnGrid())))) + itp = Interpolations.interpolate(plotdata[:, k], BSpline(Cubic(Interpolations.Line(OnGrid())))) plotdata_int[:, k] = itp.(x_plotdata) end end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index a7e0342d4..2079a0f1f 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -225,11 +225,7 @@ function PlotConfig(T::Val{:erp}) :ticklabels => false, )), ), - legend = (; - halign = :right, - valign = :center, - framevisible = false, - ), + legend = (; halign = :right, valign = :center, framevisible = false), axis = ( xlabel = "Time [s]", ylabel = "Voltage [µV]", From df0dc44a10e4a12b6210cf01601a423b9afa39a1 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:41:01 +0000 Subject: [PATCH 12/67] Update src/plot_parallelcoordinates.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/plot_parallelcoordinates.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index e48a4563c..8f2c1cb3b 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -174,7 +174,10 @@ function parallelcoordinates( x_plotdata = range(1, x_pos[end], step = 0.05) plotdata_int = Array{Float64}(undef, length(x_plotdata), size(plotdata, 2)) for k = 1:size(plotdata, 2) - itp = Interpolations.interpolate(plotdata[:, k], BSpline(Cubic(Interpolations.Line(OnGrid())))) + itp = Interpolations.interpolate( + plotdata[:, k], + BSpline(Cubic(Interpolations.Line(OnGrid()))), + ) plotdata_int[:, k] = itp.(x_plotdata) end end From 69d428052aa9bfc163ac5ee3537272852e56b686 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 13 Sep 2024 13:34:38 +0000 Subject: [PATCH 13/67] new link --- docs/literate/how_to/position2color.jl | 2 ++ docs/src/index.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/literate/how_to/position2color.jl b/docs/literate/how_to/position2color.jl index 87ac447f4..c2f7adaa6 100644 --- a/docs/literate/how_to/position2color.jl +++ b/docs/literate/how_to/position2color.jl @@ -2,6 +2,7 @@ # You want to change the colors of the lines and markers on the inserted topoplot. # To do that you need to change the color scheme (aka color map) of the butterfly plot. +# You can find th elist of colormaps for Makie [here](https://docs.makie.org/v0.21/explanations/colors). # # Setup @@ -28,6 +29,7 @@ We can change the color scale by specifying a function that maps from an `(x, y) While `RGB` & `HSV` have the advantage of being 2D color maps, `Roma0` has the advantage of being perceptually uniform. Also you can specify a uniform color. =# +# plot_butterfly( results; diff --git a/docs/src/index.md b/docs/src/index.md index 3ba1b8939..b1b3c5af0 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -17,6 +17,6 @@ The package is primarily based on [Unfold.jl](https://github.com/unfoldtoolbox/u - **Many usage examples** You can find many user-friendly examples of how to use and adapt the plots in this documentation. - **Scientific colormaps by default** -According to our study [(Mikheev, 2024)](https://apertureneuro.org/article/116386-the-art-of-brainwaves-a-survey-on-event-related-potential-visualization-practices), 40% of EEG researchers do not know about the issue of scientific color maps. As default color maps we use `Reverse(:RdBu)` (based on [colorbrewer](https://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3)) and `Roma` (based on [Sceintific Colormaps](https://www.fabiocrameri.ch/colourmaps/) by Fabio Crameri). +According to our study [(Mikheev, 2024)](https://apertureneuro.org/article/116386-the-art-of-brainwaves-a-survey-on-event-related-potential-visualization-practices), 40% of EEG researchers do not know about the issue of scientific color maps. As default color maps we use `Reverse(:RdBu)` (based on [colorbrewer](https://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3)) and `Roma` (based on [Sceintific Colormaps](https://www.fabiocrameri.ch/colourmaps/) by Fabio Crameri). - **Interactivity** Several plots make use of `Observables.jl` which allows fast updating of the underlying data. Several plots already have predefined interactive features, e.g. you can click on labels to enable / disable them. See `plot_topoplotseries` and `plot_erpimage` for examples. From 01f761ee7d92666668e5d957e1ce067be56604da Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 13 Sep 2024 13:50:23 +0000 Subject: [PATCH 14/67] renaming and more configs --- src/UnfoldMakie.jl | 6 ++--- src/plot_parallelcoordinates.jl | 1 - src/plot_spline_config.jl | 34 -------------------------- src/plot_splines.jl | 43 +++++++++++++++++++++++++++++++++ src/plotconfig.jl | 14 ++++++++++- test/test_pcp.jl | 1 + test/test_splines.jl | 2 +- 7 files changed, 61 insertions(+), 40 deletions(-) delete mode 100644 src/plot_spline_config.jl create mode 100644 src/plot_splines.jl diff --git a/src/UnfoldMakie.jl b/src/UnfoldMakie.jl index c6b1c8aa5..8f64f40ae 100644 --- a/src/UnfoldMakie.jl +++ b/src/UnfoldMakie.jl @@ -55,7 +55,7 @@ include("plot_topoplotseries.jl") include("plot_erp.jl") include("plot_butterfly.jl") include("plot_designmatrix.jl") -include("plot_spline_config.jl") +include("plot_splines.jl") include("plot_topoplot.jl") include("plot_erpimage.jl") include("plot_parallelcoordinates.jl") @@ -72,8 +72,8 @@ export PlotConfig export plot_designmatrix export plot_designmatrix! -export plot_spline_config -export plot_spline_config! +export plot_splines +export plot_splines! export plot_erp export plot_erp! export plot_erpimage diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index 8f2c1cb3b..d3bc18bae 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -8,7 +8,6 @@ Plot a PCP (parallel coordinates plot).\\ Dimensions: conditions, channels, time, trials. ## Arguments: - - `f::Union{GridPosition, GridLayout, Figure}` `Figure`, `GridLayout`, or `GridPosition` to draw the plot. - `data::Union{DataFrame, AbstractMatrix}`\\ diff --git a/src/plot_spline_config.jl b/src/plot_spline_config.jl deleted file mode 100644 index daf8d69af..000000000 --- a/src/plot_spline_config.jl +++ /dev/null @@ -1,34 +0,0 @@ -using BSplineKit, Unfold -""" - plot_spline_config(m::UnfoldModel; kwargs...) - -**Return Value:** `Figure` with spline configuration for basis functions. -""" -plot_spline_config(m::UnfoldModel; kwargs...) = plot_spline_config(Figure(), m; kwargs...) - -function plot_spline_config( - f::Union{GridPosition,GridLayout,Figure}, - m::UnfoldModel; - kwargs..., -) - splFunction = Base.get_extension(Unfold, :UnfoldBSplineKitExt).splFunction - spl_ix = findall(isa.(Unfold.formulas(m)[1].rhs.terms, Unfold.AbstractSplineTerm)) - spline_terms = Unfold.formulas(m)[1].rhs.terms[spl_ix[2]] - - x_range = - range(spline_terms.breakpoints[1], stop = spline_terms.breakpoints[2], length = 100) - basis_set = splFunction(x_range, spline_terms) - - a1 = Axis(f[1, 1]) - series!(x_range, basis_set') - - a2 = Axis(f[2, 1]) - density!( - Unfold.events(designmatrix(m))[1][:, spline_terms.term.sym]; - color = :transparent, - strokecolor = :black, - strokewidth = 1, - ) - linkxaxes!(a1, a2) - f -end diff --git a/src/plot_splines.jl b/src/plot_splines.jl new file mode 100644 index 000000000..b81125b15 --- /dev/null +++ b/src/plot_splines.jl @@ -0,0 +1,43 @@ +using BSplineKit, Unfold +""" + plot_splines(m::UnfoldModel; kwargs...) + plot_splines!(f::Union{GridPosition, GridLayout, Figure}, m::UnfoldModel; kwargs...) + +## Arguments: + +- `f::Union{GridPosition, GridLayout, Figure}` + `Figure`, `GridLayout`, or `GridPosition` to draw the plot. +- `m::UnfoldModel`\\ + UnfoldModel with splines. + +**Return Value:** `Figure` with splines and their density for basis functions. +""" +plot_splines(m::UnfoldModel; kwargs...) = plot_splines(Figure(), m; kwargs...) + +function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; kwargs...) + config = PlotConfig(:splines) + config_kwargs!(config; kwargs...) + ga = f[1, 1] = GridLayout() + @debug config + splFunction = Base.get_extension(Unfold, :UnfoldBSplineKitExt).splFunction + spl_ix = findall(isa.(Unfold.formulas(m)[1].rhs.terms, Unfold.AbstractSplineTerm)) + spline_terms = Unfold.formulas(m)[1].rhs.terms[spl_ix[2]] + + x_range = + range(spline_terms.breakpoints[1], stop = spline_terms.breakpoints[2], length = 100) + basis_set = splFunction(x_range, spline_terms) + + a1 = Axis(ga[1, 1]; xlabelvisible = false, xticklabelsvisible = false) + series!(x_range, basis_set', color = config.visual.colormap) + f[1, 2] = Legend(ga[1, 1], a1, config.legend.title; config.legend...) + + a2 = Axis(ga[2, 1]; xautolimitmargin = (0, 0), config.axis...) + density!( + Unfold.events(designmatrix(m))[1][:, spline_terms.term.sym]; + color = :transparent, + strokecolor = :black, + strokewidth = 1, + ) + linkxaxes!(a1, a2) + f +end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 2079a0f1f..09e0e1793 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -28,7 +28,6 @@ function PlotConfig()# defaults (;), # axis (; # layout show_legend = true, - legend_position = :right, use_colorbar = false, # ideally should be deleted ), (#maping @@ -183,6 +182,18 @@ function PlotConfig(T::Val{:designmat}) return cfg end +function PlotConfig(T::Val{:splines}) + cfg = PlotConfig() + config_kwargs!( + cfg; + layout = (;), + axis = (; xlabel = "Range", ylabel = "Density"), + visual = (; colormap = Makie.wong_colors()), + legend = (; title = "Splines", framevisible = false), + ) + return cfg +end + function PlotConfig(T::Val{:butterfly}) cfg = PlotConfig(:erp) config_kwargs!( @@ -289,6 +300,7 @@ function PlotConfig(T::Val{:paracoord}) axis = (; xlabel = "Channels", ylabel = "Time", title = ""), legend = (; title = "Conditions", merge = true, framevisible = false), # fontsize = 14), mapping = (; x = :channel), + layout = (; legend_position = :right), ) return cfg end diff --git a/test/test_pcp.jl b/test/test_pcp.jl index 84a3063b8..83cbc09ec 100644 --- a/test/test_pcp.jl +++ b/test/test_pcp.jl @@ -1,5 +1,6 @@ include("../docs/example_data.jl") # we need more specified example data results_plot, positions = example_data() + @testset "PCP: data input DataFrame" begin plot_parallelcoordinates(results_plot) end diff --git a/test/test_splines.jl b/test/test_splines.jl index 6612b26ca..bb1874d13 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -2,7 +2,7 @@ using BSplineKit, Unfold m = example_data("UnfoldLinearModelwithSpline") @testset "Spline plot: basic" begin - plot_spline_config(m) + plot_splines(m) end #= rng = MersenneTwister(2) # make repeatable From f6e0fc9bfc2e57a6c2934b6bd80571dec9c65e07 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 13 Sep 2024 15:06:26 +0000 Subject: [PATCH 15/67] simplification of layout helper and issue 225 --- docs/literate/how_to/position2color.jl | 7 +++--- docs/literate/tutorials/topoplot.jl | 2 +- src/layout_helper.jl | 35 +------------------------- src/plot_erpimage.jl | 2 +- src/plot_parallelcoordinates.jl | 7 ++++-- src/plotconfig.jl | 6 +++-- test/test_pcp.jl | 8 ++++++ 7 files changed, 23 insertions(+), 44 deletions(-) diff --git a/docs/literate/how_to/position2color.jl b/docs/literate/how_to/position2color.jl index c2f7adaa6..956097d3b 100644 --- a/docs/literate/how_to/position2color.jl +++ b/docs/literate/how_to/position2color.jl @@ -25,11 +25,10 @@ We can change the color scale by specifying a function that maps from an `(x, y) - `pos2colorRGB` (same as MNE-Python), - `pos2colorHSV` (HSV color space), - `pos2colorRomaO`. - -While `RGB` & `HSV` have the advantage of being 2D color maps, `Roma0` has the advantage of being perceptually uniform. -Also you can specify a uniform color. =# -# +# While `RGB` & `HSV` have the advantage of being 2D color maps, `Roma0` has the advantage of being perceptually uniform. +# Also you can specify a uniform color. + plot_butterfly( results; diff --git a/docs/literate/tutorials/topoplot.jl b/docs/literate/tutorials/topoplot.jl index abb67b0c2..98c40b4a6 100644 --- a/docs/literate/tutorials/topoplot.jl +++ b/docs/literate/tutorials/topoplot.jl @@ -95,4 +95,4 @@ f # ```@docs # plot_topoplot -# ``` \ No newline at end of file +# ``` diff --git a/src/layout_helper.jl b/src/layout_helper.jl index 628bf8267..f6a67f228 100644 --- a/src/layout_helper.jl +++ b/src/layout_helper.jl @@ -9,43 +9,12 @@ function apply_layout_settings!( hm = nothing, drawing = nothing, ax = nothing, - plotArea = (1, 1), + plot_area = (1, 1), ) if isnothing(ax) ax = current_axis() end - if (config.layout.show_legend) - if isnothing(fig) - @error "Legend needs `Figure` parameter" - else - # set f[] position depending on legend_position - legend_position = - config.layout.legend_position == :right ? - fig[1:plotArea[1], plotArea[2]+1] : fig[plotArea[1]+1, 1:plotArea[2]] - if isnothing(drawing) - if (config.layout.use_colorbar) #not sure this line is useful - if isnothing(hm) - Colorbar( - legend_position; - colormap = config.visual.colormap, - config.colorbar..., - ) - else - Colorbar(legend_position, hm; config.colorbar...) - end - else # for PCP - title_pcp = getproperty.(Ref(config.legend), :title) # pop title - config.legend = dropnames(config.legend, (:title,)) # delete title - Legend(legend_position, ax, title_pcp; config.legend...) - end - else - legend!(legend_position, drawing; config.legend...) - colorbar!(legend_position, drawing; config.colorbar...) - end - end - end - if :hidespines ∈ keys(config.layout) && !isnothing(config.layout.hidespines) Makie.hidespines!(ax, config.layout.hidespines...) end @@ -58,6 +27,4 @@ Makie.hidedecorations!(ax::Matrix{AxisEntries}; kwargs...) = Makie.hidedecorations!.(ax; kwargs...) Makie.hidespines!(ax::Matrix{AxisEntries}, args...) = Makie.hidespines!.(ax, args...) -#hidedecorations!(ax::AxisEntries;kwargs...) = Makie.hidedecorations!.(ax.axis;kwargs...) Makie.hidespines!(ax::AxisEntries, args...) = Makie.hidespines!.(ax.axis, args...) -#hidespinses!(ax:Axis,args...) = hiespines!.(Ref(ax),args...) diff --git a/src/plot_erpimage.jl b/src/plot_erpimage.jl index 5cf4d1abb..7847c796d 100644 --- a/src/plot_erpimage.jl +++ b/src/plot_erpimage.jl @@ -125,7 +125,7 @@ function plot_erpimage!( ) end hidespines!(ax, :r, :t) - apply_layout_settings!(config; fig = f, hm = hm, ax = ax, plotArea = (4, 1)) + apply_layout_settings!(config; fig = f, hm = hm, ax = ax, plot_area = (4, 1)) return f end diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index d3bc18bae..67ead8492 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -100,7 +100,7 @@ function plot_parallelcoordinates( end UnfoldMakie.config_kwargs!(config; visual = (; color = c)) - f, ax, axlist, hlines = parallelcoordinates( + f1, ax, axlist, hlines = parallelcoordinates( f, d5; normalize = normalize, @@ -118,7 +118,10 @@ function plot_parallelcoordinates( fontsize = 20, font = :bold, ) - apply_layout_settings!(config; fig = f, ax = ax) + if config.layout.show_legend + Legend(f[1, 2], ax, config.legend.title; config.legend...) + end + apply_layout_settings!(config; fig = f1, ax = ax) return isa(f, Figure) ? Makie.FigureAxisPlot(f, [ax, axlist], hlines[1]) : Makie.AxisPlot([ax, axlist], hlines[1]) diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 09e0e1793..b5e3febe5 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -41,6 +41,8 @@ function PlotConfig()# defaults orientation = :vertical, tellwidth = true, tellheight = false, + halign = :right, + valign = :center, ), (;#colorbar vertical = true, @@ -236,7 +238,7 @@ function PlotConfig(T::Val{:erp}) :ticklabels => false, )), ), - legend = (; halign = :right, valign = :center, framevisible = false), + legend = (; framevisible = false), axis = ( xlabel = "Time [s]", ylabel = "Voltage [µV]", @@ -300,7 +302,7 @@ function PlotConfig(T::Val{:paracoord}) axis = (; xlabel = "Channels", ylabel = "Time", title = ""), legend = (; title = "Conditions", merge = true, framevisible = false), # fontsize = 14), mapping = (; x = :channel), - layout = (; legend_position = :right), + layout = (; show_legend = true), ) return cfg end diff --git a/test/test_pcp.jl b/test/test_pcp.jl index 83cbc09ec..508dd8a7b 100644 --- a/test/test_pcp.jl +++ b/test/test_pcp.jl @@ -16,6 +16,14 @@ end plot_parallelcoordinates(results_plot; mapping = (color = :coefname, y = :estimate)) end +@testset "PCP: show_legend = false" begin + plot_parallelcoordinates( + results_plot; + mapping = (color = :coefname, y = :estimate), + layout = (; show_legend = false), + ) +end + @testset "PCP: Figure, 64 channels, 1 condition, bigger size" begin plot_parallelcoordinates( Figure(size = (1200, 800)), From d2b6d6a34526fc74bbd79dd93db8195bcd4976c5 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 13 Sep 2024 15:25:18 +0000 Subject: [PATCH 16/67] failed to do multilaine comment in Literate --- docs/literate/how_to/position2color.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/literate/how_to/position2color.jl b/docs/literate/how_to/position2color.jl index 956097d3b..3d3448005 100644 --- a/docs/literate/how_to/position2color.jl +++ b/docs/literate/how_to/position2color.jl @@ -20,12 +20,12 @@ plot_butterfly(results; positions = positions) # # Color schemes # ## MNE style -#= -We can change the color scale by specifying a function that maps from an `(x, y)` tuple to a color. UnfoldMakie currently provides three different color scales: -- `pos2colorRGB` (same as MNE-Python), -- `pos2colorHSV` (HSV color space), -- `pos2colorRomaO`. -=# +# We can change the color scale by specifying a function that maps from an `(x, y)` tuple to a color. +# `UnfoldMakie` currently provides three different color scales: +# - `pos2colorRGB` (same as MNE-Python), +# - `pos2colorHSV` (HSV color space), +# - `pos2colorRomaO`. + # While `RGB` & `HSV` have the advantage of being 2D color maps, `Roma0` has the advantage of being perceptually uniform. # Also you can specify a uniform color. From 01e8c1c378ae988f0337f61c232296461a4b8eaf Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 09:58:51 +0000 Subject: [PATCH 17/67] sterror issues 55 nad 238 --- src/plot_erp.jl | 26 ++++++++++++++++++++------ test/test_erp.jl | 22 +++++++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 84fbd6f58..993693117 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -85,11 +85,8 @@ function plot_erp!( plot_data.group = plot_data.group .|> a -> isnothing(a) ? :fixef : a end - # check if stderror values exist and create new columns with high and low band - if "stderror" ∈ names(plot_data) && stderror - plot_data.stderror = plot_data.stderror .|> a -> isnothing(a) ? 0.0 : a - plot_data[!, :se_low] = plot_data[:, config.mapping.y] .- plot_data.stderror - plot_data[!, :se_high] = plot_data[:, config.mapping.y] .+ plot_data.stderror + if "group" ∈ names(plot_data) + plot_data.group = plot_data.group .|> a -> isnothing(a) ? :fixef : a end # automatically convert col & group to nonnumeric @@ -110,15 +107,32 @@ function plot_erp!( merge(config.mapping, (; group = config.mapping.group => nonnumeric)) end + # check if stderror values exist and create new columns with high and low band + if "stderror" ∈ names(plot_data) && stderror + plot_data.stderror = plot_data.stderror .|> a -> isnothing(a) ? 0.0 : a + plot_data[!, :se_low] = plot_data[:, config.mapping.y] .- plot_data.stderror + plot_data[!, :se_high] = plot_data[:, config.mapping.y] .+ plot_data.stderror + end + mapp = AlgebraOfGraphics.mapping() + if (:color ∈ keys(config.mapping)) + mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.color) + end + if (:group ∈ keys(config.mapping)) + mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.group) + end + if (:col ∈ keys(config.mapping)) + mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.col) + end + # remove x / y mapping_others = deleteKeys(config.mapping, [:x, :y, :positions, :lables]) - xy_mapp = AlgebraOfGraphics.mapping(config.mapping.x, config.mapping.y; mapping_others...) basic = visual(Lines; config.visual...) * xy_mapp # add band of sdterrors + if stderror m_se = AlgebraOfGraphics.mapping(config.mapping.x, :se_low, :se_high) basic = basic + visual(Band, alpha = 0.5) * m_se diff --git a/test/test_erp.jl b/test/test_erp.jl index cd0bacb93..6735c0aef 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -1,11 +1,16 @@ +using Unfold: stderror using AlgebraOfGraphics: group include("../docs/example_data.jl") m = example_data("UnfoldLinearModel") + results = coeftable(m) res_effects = effects(Dict(:continuous => -5:0.5:5), m) res_effects2 = effects(Dict(:condition => ["car", "face"], :continuous => -5:5), m) dat, positions = TopoPlots.example_data() +m7 = example_data("7channels") +results7 = coeftable(m7) + @testset "ERP plot: DataFrame data" begin plot_erp(results) end @@ -32,13 +37,13 @@ end end @testset "ERP plot: stderror error" begin - plot_erp(results; :stderror => true) + plot_erp(results; stderror = true) end @testset "ERP plot: standart errors in GridLayout" begin f = Figure(size = (1200, 1400)) ga = f[1, 1] = GridLayout() - plot_erp!(ga, results; :stderror => true) + plot_erp!(ga, results; stderror = true) f end @@ -48,6 +53,12 @@ end plot_erp(results; mapping = (; col = :group)) end +@testset "ERP plot: faceting by two columns with stderror" begin + results = coeftable(m) + results.group = push!(repeat(["A", "B"], inner = 67), "A") + plot_erp(results; mapping = (; col = :group), stderror = true) +end + @testset "ERP plot: with and withour error ribbons" begin results = coeftable(m) results.coefname = @@ -59,14 +70,14 @@ end f[1, 1], results; axis = (; title = "Bad example", titlegap = 12), - :stderror => false, + stderror = false, mapping = (; color = :coefname => "Conditions"), ) plot_erp!( f[2, 1], results; axis = (title = "Good example", titlegap = 12), - :stderror => true, + stderror = true, mapping = (; color = :coefname => "Conditions"), ) @@ -104,8 +115,6 @@ end end @testset "ERP plot: 7 channels faceted" begin - m7 = example_data("7channels") - results7 = coeftable(m7) plot_erp(results7, mapping = (; col = :channel, group = :channel)) end @@ -119,7 +128,6 @@ end f, results; axis = (title = "Bad example", titlegap = 12), - :stderror => false, mapping = (; color = :coefname => "Conditions"), ) f From e2d9f7d89859a2b152cbeea5dfa0845aae2089af Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 10:26:46 +0000 Subject: [PATCH 18/67] additional parameters --- src/plot_erp.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 993693117..9ae21791b 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -115,7 +115,14 @@ function plot_erp!( end mapp = AlgebraOfGraphics.mapping() + #= for i in [:color, :group, :col] + if (i ∈ keys(config.mapping)) + tmp = getindex(config.mapping, i) + mapp = mapp * AlgebraOfGraphics.mapping(; tmp ) + end + end haven't solved it yet =# + #mapping for stderrors if (:color ∈ keys(config.mapping)) mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.color) end @@ -125,9 +132,16 @@ function plot_erp!( if (:col ∈ keys(config.mapping)) mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.col) end + if (:row ∈ keys(config.mapping)) + mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.row) + end + if (:row ∈ keys(config.layout)) + mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.layout) + end # remove x / y mapping_others = deleteKeys(config.mapping, [:x, :y, :positions, :lables]) + xy_mapp = AlgebraOfGraphics.mapping(config.mapping.x, config.mapping.y; mapping_others...) basic = visual(Lines; config.visual...) * xy_mapp From d2e5bd86ea0a116397449f4a281da33048bc684f Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 10:27:55 +0000 Subject: [PATCH 19/67] bug --- src/plot_erp.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 9ae21791b..d3ca7c569 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -122,7 +122,7 @@ function plot_erp!( end end haven't solved it yet =# - #mapping for stderrors + # mapping for stderrors if (:color ∈ keys(config.mapping)) mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.color) end @@ -135,7 +135,7 @@ function plot_erp!( if (:row ∈ keys(config.mapping)) mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.row) end - if (:row ∈ keys(config.layout)) + if (:layout ∈ keys(config.layout)) mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.layout) end From f760562d6db7d035d016d74fb6fe94e0a90858fb Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 12:29:43 +0000 Subject: [PATCH 20/67] multiple splines --- docs/example_data.jl | 19 ++++++++++++-- src/plot_splines.jl | 61 +++++++++++++++++++++++++++++--------------- src/plotconfig.jl | 4 +-- test/test_splines.jl | 9 +++++-- 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/docs/example_data.jl b/docs/example_data.jl index 4f114f74e..f90060d1f 100644 --- a/docs/example_data.jl +++ b/docs/example_data.jl @@ -33,7 +33,23 @@ function example_data(example = "TopoPlots.jl") data; solver = se_solver, ) - elseif example == "UnfoldLinearModelwithSpline" + elseif example == "UnfoldLinearModelwith1Spline" + # load and generate a simulated Unfold Design + data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) + data = reshape(data, (1, size(data)...)) + evts.continuous2 .= + log10.(6 .+ rand(MersenneTwister(1), length(evts.continuous))) .^ 2 + f = @formula 0 ~ 1 + condition + spl(continuous, 4) + # generate ModelStruct + se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) + return fit( + UnfoldModel, + [Any => (f, range(0, length = size(data, 2), step = 1 / 100))], + evts, + data; + solver = se_solver, + ) + elseif example == "UnfoldLinearModelwith2Splines" # load and generate a simulated Unfold Design data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) data = reshape(data, (1, size(data)...)) @@ -49,7 +65,6 @@ function example_data(example = "TopoPlots.jl") data; solver = se_solver, ) - elseif example == "UnfoldLinearModelMultiChannel" # load and generate a simulated Unfold Design cAll = DataFrame() diff --git a/src/plot_splines.jl b/src/plot_splines.jl index b81125b15..8573359ae 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -1,5 +1,6 @@ using BSplineKit, Unfold """ +using Unfold: terms plot_splines(m::UnfoldModel; kwargs...) plot_splines!(f::Union{GridPosition, GridLayout, Figure}, m::UnfoldModel; kwargs...) @@ -18,26 +19,46 @@ function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; config = PlotConfig(:splines) config_kwargs!(config; kwargs...) ga = f[1, 1] = GridLayout() - @debug config + + terms = Unfold.formulas(m)[1].rhs.terms + spl_title = join(terms, " + ") + splFunction = Base.get_extension(Unfold, :UnfoldBSplineKitExt).splFunction - spl_ix = findall(isa.(Unfold.formulas(m)[1].rhs.terms, Unfold.AbstractSplineTerm)) - spline_terms = Unfold.formulas(m)[1].rhs.terms[spl_ix[2]] - - x_range = - range(spline_terms.breakpoints[1], stop = spline_terms.breakpoints[2], length = 100) - basis_set = splFunction(x_range, spline_terms) - - a1 = Axis(ga[1, 1]; xlabelvisible = false, xticklabelsvisible = false) - series!(x_range, basis_set', color = config.visual.colormap) - f[1, 2] = Legend(ga[1, 1], a1, config.legend.title; config.legend...) - - a2 = Axis(ga[2, 1]; xautolimitmargin = (0, 0), config.axis...) - density!( - Unfold.events(designmatrix(m))[1][:, spline_terms.term.sym]; - color = :transparent, - strokecolor = :black, - strokewidth = 1, - ) - linkxaxes!(a1, a2) + spl_ix = findall(isa.(terms, Unfold.AbstractSplineTerm)) + + spline_terms = [terms[i] for i in spl_ix] + j = 1 + for i in spline_terms + x_range = range(i.breakpoints[1], stop = i.breakpoints[2], length = 100) + basis_set = splFunction(x_range, i) + tmp = "Spline value" + if j > 1 + config_kwargs!(config; axis = (; ylabelvisible = false)) + tmp = "" + end + a1 = Axis( + ga[1, j]; + title = string(i), + ylabel = tmp, + xlabelvisible = false, + xticklabelsvisible = false, + ) + series!(x_range, basis_set', color = config.visual.colormap) + + + a2 = Axis(ga[2, j]; xautolimitmargin = (0, 0), config.axis...) + density!( + Unfold.events(designmatrix(m))[1][:, i.term.sym]; + color = :transparent, + strokecolor = :black, + strokewidth = 1, + ) + linkxaxes!(a1, a2) + j = j + 1 + end + + supertitle = + Label(ga[1, 1:end, Top()], spl_title, fontsize = 20, padding = (0, 0, 40, 0)) + f end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index b5e3febe5..3ec9002b8 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -189,8 +189,8 @@ function PlotConfig(T::Val{:splines}) config_kwargs!( cfg; layout = (;), - axis = (; xlabel = "Range", ylabel = "Density"), - visual = (; colormap = Makie.wong_colors()), + axis = (; xlabel = "Range", ylabel = "Density value"), + visual = (; colormap = :viridis), legend = (; title = "Splines", framevisible = false), ) return cfg diff --git a/test/test_splines.jl b/test/test_splines.jl index bb1874d13..f4d36f841 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -1,8 +1,13 @@ using BSplineKit, Unfold -m = example_data("UnfoldLinearModelwithSpline") +m1 = example_data("UnfoldLinearModelwith1Spline") +m2 = example_data("UnfoldLinearModelwith2Splines") @testset "Spline plot: basic" begin - plot_splines(m) + plot_splines(m1) +end + +@testset "Spline plot: basic" begin + plot_splines(m2) end #= rng = MersenneTwister(2) # make repeatable From b09280327b052d8d55f9777a6304c5dad8b9ffff Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 17:30:14 +0000 Subject: [PATCH 21/67] knots and contionous colors implemented --- docs/example_data.jl | 2 +- src/plot_parallelcoordinates.jl | 7 +-- src/plot_splines.jl | 75 +++++++++++++++++++++++++-------- test/test_pcp.jl | 19 --------- test/test_splines.jl | 2 + 5 files changed, 63 insertions(+), 42 deletions(-) diff --git a/docs/example_data.jl b/docs/example_data.jl index f90060d1f..ef67f50bd 100644 --- a/docs/example_data.jl +++ b/docs/example_data.jl @@ -55,7 +55,7 @@ function example_data(example = "TopoPlots.jl") data = reshape(data, (1, size(data)...)) evts.continuous2 .= log10.(6 .+ rand(MersenneTwister(1), length(evts.continuous))) .^ 2 - f = @formula 0 ~ 1 + condition + spl(continuous, 4) + spl(continuous2, 4) + f = @formula 0 ~ 1 + condition + spl(continuous, 4) + spl(continuous2, 6) # generate ModelStruct se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) return fit( diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index 67ead8492..72d822324 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -193,14 +193,12 @@ function parallelcoordinates( # categorical colors un_c = unique(color) color_ix = [findfirst(un_c .== c) for c in color] - #@assert length(un_c) == 1 "Only single color found, please don't specify color, " if length(un_c) == 1 - @warn "Only single unique value found in the specified color vector" - color = cgrad(colormap, 2)[color_ix] + @warn "Only single unique value found in the specified color vector." + color = cgrad(colormap, 2)[color_ix] # color gradient else color = cgrad(colormap, length(un_c))[color_ix] end - #crange = [1,length(unique(color))] else # continuous color crange = [minimum(color), maximum(color)] @@ -210,7 +208,6 @@ function parallelcoordinates( # plot the lines - this way it will be easy to curve them too hlines = [] for (ix, r) in enumerate(eachcol(plotdata_int)) - h = lines!( ax, x_plotdata, diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 8573359ae..c5bfe0519 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -1,9 +1,11 @@ using BSplineKit, Unfold """ -using Unfold: terms plot_splines(m::UnfoldModel; kwargs...) plot_splines!(f::Union{GridPosition, GridLayout, Figure}, m::UnfoldModel; kwargs...) +Shows two subfigures. First, baseses of splines. Second, density of splines.\\ +Dashed lines shows spline knots. + ## Arguments: - `f::Union{GridPosition, GridLayout, Figure}` @@ -27,38 +29,77 @@ function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; spl_ix = findall(isa.(terms, Unfold.AbstractSplineTerm)) spline_terms = [terms[i] for i in spl_ix] - j = 1 - for i in spline_terms - x_range = range(i.breakpoints[1], stop = i.breakpoints[2], length = 100) - basis_set = splFunction(x_range, i) - tmp = "Spline value" - if j > 1 + subplot_id = 1 + for spline_term in spline_terms + #basises = BSplineBasis(BSplineOrder(i.order), i.breakpoints) + #knots = BSplineKit.knots(basises) + x_range = range( + spline_term.breakpoints[1], + stop = spline_term.breakpoints[end], + length = 100, + ) + basis_set = splFunction(x_range, spline_term) + + ylabel_first = "Spline value" + if subplot_id > 1 config_kwargs!(config; axis = (; ylabelvisible = false)) - tmp = "" + ylabel_first = "" end a1 = Axis( - ga[1, j]; - title = string(i), - ylabel = tmp, + ga[1, subplot_id]; + title = string(spline_term), + ylabel = ylabel_first, xlabelvisible = false, xticklabelsvisible = false, ) - series!(x_range, basis_set', color = config.visual.colormap) - + series!( + x_range, + basis_set', + color = resample_cmap(config.visual.colormap, size(basis_set')[1]), + ) #contionus colormap used + vlines!( + spline_term.breakpoints; + ymin = extrema(basis_set')[1], + ymax = extrema(basis_set')[2], + linestyle = :dash, + ) + #scatter!(spline_term.breakpoints, [0,0,0,0,0,0,0,0]; markersize = 10, strokecolor = :tomato, strokewidth = 3) - a2 = Axis(ga[2, j]; xautolimitmargin = (0, 0), config.axis...) + a2 = Axis(ga[2, subplot_id]; xautolimitmargin = (0, 0), config.axis...) density!( - Unfold.events(designmatrix(m))[1][:, i.term.sym]; + Unfold.events(designmatrix(m))[1][:, spline_term.term.sym]; color = :transparent, strokecolor = :black, strokewidth = 1, ) linkxaxes!(a1, a2) - j = j + 1 + subplot_id = subplot_id + 1 end supertitle = Label(ga[1, 1:end, Top()], spl_title, fontsize = 20, padding = (0, 0, 40, 0)) - f end + +#= crange = [1, 2] # default + if isnothing(color) + color = 1 + elseif isa(color, AbstractVector) + if isa(color[1], String) + # categorical colors + un_c = unique(color) + color_ix = [findfirst(un_c .== c) for c in color] + #@assert length(un_c) == 1 "Only single color found, please don't specify color, " + if length(un_c) == 1 + @warn "Only single unique value found in the specified color vector" + color = cgrad(config.visual.colormap, 2)[color_ix] + else + color = cgrad(config.visual.colormap, length(un_c))[color_ix] + end + #crange = [1,length(unique(color))] + else + # continuous color + crange = [minimum(color), maximum(color)] + end + end + =# diff --git a/test/test_pcp.jl b/test/test_pcp.jl index 508dd8a7b..28016b181 100644 --- a/test/test_pcp.jl +++ b/test/test_pcp.jl @@ -211,22 +211,3 @@ end ) f end - -begin - f = Figure() - plot_parallelcoordinates( - f[1, 1], - subset(results_plot, :channel => x -> x .< 10); - mapping = (; color = :coefname), - axis = (; title = "normalize = nothing"), - ) - plot_parallelcoordinates( - f[2, 1], - subset(results_plot, :channel => x -> x .< 10); - mapping = (; color = :coefname), - normalize = :minmax, - axis = (; title = "normalize = :minmax"), - ) - f - -end diff --git a/test/test_splines.jl b/test/test_splines.jl index f4d36f841..2f59b4e23 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -28,3 +28,5 @@ ax = Axis(Figure()[1, 1]) [lines!(ax, basisSet[:, k]) for k = 1:size(basisSet, 2)] current_figure() =# + +knots(BSplineBasis(BSplineOrder(1), [0.6055842565094224, 0.7141858385002271])) From 5dff5acfd98f4bb5a2b3d5d30cf1eb5bc329341a Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 17:40:46 +0000 Subject: [PATCH 22/67] spline docs --- docs/Project.toml | 3 ++- docs/literate/tutorials/splines.jl | 24 ++++++++++++++++++++++++ docs/make.jl | 1 + docs/src/index.md | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 docs/literate/tutorials/splines.jl diff --git a/docs/Project.toml b/docs/Project.toml index 7064ee367..616490bae 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,6 @@ [deps] AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67" +BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" @@ -23,4 +24,4 @@ UnfoldSim = "ed8ae6d2-84d3-44c6-ab46-0baf21700804" XML2_jll = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" [compat] -AlgebraOfGraphics = "0.7, 0.8" \ No newline at end of file +AlgebraOfGraphics = "0.7, 0.8" diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl new file mode 100644 index 000000000..cec0fd4c1 --- /dev/null +++ b/docs/literate/tutorials/splines.jl @@ -0,0 +1,24 @@ +# # [Spline plot](@id spline_vis) +# **Spline plot** (aka topography plot) is a plot type for visualisation of spline basises. + + +# # Setup +# Package and data loading + +using Unfold, UnfoldMakie +using BSplineKit +m1 = example_data("../../../UnfoldLinearModelwith1Spline") +m2 = example_data("../../../UnfoldLinearModelwith2Splines") + + +# Spline plot with one spline term +plot_splines(m1) + +# Spline plot with two spline terms +plot_splines(m2) + +# # Configurations of Butterfly Plot + +# ```@docs +# plot_splines +# ``` \ No newline at end of file diff --git a/docs/make.jl b/docs/make.jl index 43a140fe4..37265bceb 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -50,6 +50,7 @@ makedocs(; "Channel image" => "generated/tutorials/channel_image.md", "Parallel coordinates" => "generated/tutorials/parallelcoordinates.md", "Design matrix" => "generated/tutorials/designmatrix.md", + "Spline plot" => "generated/tutorials/splines.md", "Circular topoplots" => "generated/tutorials/circ_topo.md", ], "How To" => [ diff --git a/docs/src/index.md b/docs/src/index.md index b1b3c5af0..1a6d58890 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -8,7 +8,7 @@ This is the documentation of the UnfoldMakie.jl package for the Julia programmin ## Highlights of UnfoldMakie.jl -- **10 plot functions for displaying ERPs.** +- **11 plot functions for displaying ERPs.** Each plot emphasizes certain dimensions while collapsing others. - **Fast plotting** Plot one figure with 20 topoplots in 1 second? No problemo! From 3dda76b96a933cafc562accec0f024006e23d1d0 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 17:44:43 +0000 Subject: [PATCH 23/67] tiny cleaning --- docs/literate/tutorials/splines.jl | 2 +- test/test_splines.jl | 27 +++------------------------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl index cec0fd4c1..5d22c9fe4 100644 --- a/docs/literate/tutorials/splines.jl +++ b/docs/literate/tutorials/splines.jl @@ -21,4 +21,4 @@ plot_splines(m2) # ```@docs # plot_splines -# ``` \ No newline at end of file +# ``` diff --git a/test/test_splines.jl b/test/test_splines.jl index 2f59b4e23..1e2d73921 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -2,31 +2,10 @@ using BSplineKit, Unfold m1 = example_data("UnfoldLinearModelwith1Spline") m2 = example_data("UnfoldLinearModelwith2Splines") -@testset "Spline plot: basic" begin +@testset "Spline plot: basic" begin plot_splines(m1) end -@testset "Spline plot: basic" begin +@testset "Spline plot: two spline terms" begin plot_splines(m2) -end - -#= rng = MersenneTwister(2) # make repeatable -n = 20 # datapoints -evts = DataFrame(:x => rand(rng, n)) -signal = -(3 * (evts.x .- 0.5)) .^ 2 .+ 0.5 .* rand(rng, n) -signal = reshape(signal, length(signal), 1, 1) -signal = permutedims(signal, [3, 2, 1]) -design_spl10 = [Any => (@formula(0 ~ 1 + spl(x, 10)), [0])]; - -uf_spl10 = fit(UnfoldModel, design_spl10, evts, signal); -term_spl = Unfold.formulas(uf_spl10)[1].rhs.terms[2] - -basisSet = splFunction(0.0:0.01:1, term_spl) - -basisSet = disallowmissing(basisSet[.!any(ismissing.(basisSet), dims = 2)[:, 1], :]) # remove missings -ax = Axis(Figure()[1, 1]) -[lines!(ax, basisSet[:, k]) for k = 1:size(basisSet, 2)] -current_figure() - =# - -knots(BSplineBasis(BSplineOrder(1), [0.6055842565094224, 0.7141858385002271])) +end \ No newline at end of file From cc75a233cf09f7d842dac4f303efa88cfd669940 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 18:10:07 +0000 Subject: [PATCH 24/67] bug --- docs/literate/tutorials/splines.jl | 8 ++++++-- src/plot_splines.jl | 3 +-- src/plotconfig.jl | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl index 5d22c9fe4..e0ed02327 100644 --- a/docs/literate/tutorials/splines.jl +++ b/docs/literate/tutorials/splines.jl @@ -7,8 +7,12 @@ using Unfold, UnfoldMakie using BSplineKit -m1 = example_data("../../../UnfoldLinearModelwith1Spline") -m2 = example_data("../../../UnfoldLinearModelwith2Splines") + + +include("../../../example_data.jl") +df, pos = example_data("TopoPlots.jl") +m1 = example_data("UnfoldLinearModelwith1Spline") +m2 = example_data("UnfoldLinearModelwith2Splines") # Spline plot with one spline term diff --git a/src/plot_splines.jl b/src/plot_splines.jl index c5bfe0519..47f91da88 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -64,8 +64,7 @@ function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; linestyle = :dash, ) #scatter!(spline_term.breakpoints, [0,0,0,0,0,0,0,0]; markersize = 10, strokecolor = :tomato, strokewidth = 3) - - a2 = Axis(ga[2, subplot_id]; xautolimitmargin = (0, 0), config.axis...) + a2 = Axis(ga[2, subplot_id]; xlabel = string(spline_term.term.sym), xautolimitmargin = (0, 0), config.axis...) density!( Unfold.events(designmatrix(m))[1][:, spline_term.term.sym]; color = :transparent, diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 3ec9002b8..35dfe6566 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -189,7 +189,7 @@ function PlotConfig(T::Val{:splines}) config_kwargs!( cfg; layout = (;), - axis = (; xlabel = "Range", ylabel = "Density value"), + axis = (; ylabel = "Density value"), visual = (; colormap = :viridis), legend = (; title = "Splines", framevisible = false), ) From fb3f2888bf40699625b8fb505eff78cf132ca502 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Mon, 16 Sep 2024 20:25:11 +0200 Subject: [PATCH 25/67] Update src/plot_splines.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/plot_splines.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 47f91da88..964c5db81 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -64,7 +64,12 @@ function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; linestyle = :dash, ) #scatter!(spline_term.breakpoints, [0,0,0,0,0,0,0,0]; markersize = 10, strokecolor = :tomato, strokewidth = 3) - a2 = Axis(ga[2, subplot_id]; xlabel = string(spline_term.term.sym), xautolimitmargin = (0, 0), config.axis...) + a2 = Axis( + ga[2, subplot_id]; + xlabel = string(spline_term.term.sym), + xautolimitmargin = (0, 0), + config.axis..., + ) density!( Unfold.events(designmatrix(m))[1][:, spline_term.term.sym]; color = :transparent, From 442d53978e1b3e1677dc3af479dda2cb605983bb Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 19:21:43 +0000 Subject: [PATCH 26/67] doc bug --- docs/literate/tutorials/splines.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl index e0ed02327..9c3ba4371 100644 --- a/docs/literate/tutorials/splines.jl +++ b/docs/literate/tutorials/splines.jl @@ -6,7 +6,7 @@ # Package and data loading using Unfold, UnfoldMakie -using BSplineKit +using BSplineKit, DataFrames include("../../../example_data.jl") From d28a6eee82c1c0df7a52045503979c24169ced4d Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 16 Sep 2024 19:40:32 +0000 Subject: [PATCH 27/67] hide --- docs/literate/tutorials/splines.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl index 9c3ba4371..34e3ce2e7 100644 --- a/docs/literate/tutorials/splines.jl +++ b/docs/literate/tutorials/splines.jl @@ -11,8 +11,8 @@ using BSplineKit, DataFrames include("../../../example_data.jl") df, pos = example_data("TopoPlots.jl") -m1 = example_data("UnfoldLinearModelwith1Spline") -m2 = example_data("UnfoldLinearModelwith2Splines") +m1 = example_data("UnfoldLinearModelwith1Spline"); +m2 = example_data("UnfoldLinearModelwith2Splines"); # Spline plot with one spline term From 7e3b0c6a06beef9f044d3b3a4aca6bc9f94f3308 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 17 Sep 2024 09:48:00 +0000 Subject: [PATCH 28/67] formatting --- docs/literate/explanations/positions.jl | 2 +- docs/literate/intro/code_principles.jl | 12 ++++++------ docs/literate/tutorials/designmatrix.jl | 2 +- docs/literate/tutorials/erp.jl | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/literate/explanations/positions.jl b/docs/literate/explanations/positions.jl index f1623215b..c927b62c7 100644 --- a/docs/literate/explanations/positions.jl +++ b/docs/literate/explanations/positions.jl @@ -4,7 +4,7 @@ using UnfoldMakie using CairoMakie using TopoPlots -using PyMNE +using PyMNE; # # Get positions from MNE diff --git a/docs/literate/intro/code_principles.jl b/docs/literate/intro/code_principles.jl index 3ac8df4b5..6f15e4aaf 100644 --- a/docs/literate/intro/code_principles.jl +++ b/docs/literate/intro/code_principles.jl @@ -3,9 +3,9 @@ # Here we will write about principles which we developed through our publication. -#- Code should be clear and concise -#- Variables inside the code should have meaningful names -#- Every function exposed to the user should have documentation that specifies all parameters, types, input and output arguments. -#- Most people will not look at the defaults, so it is very important to nudge users to show important details with a picture or text. -#- Function naming should be based on some theory and naming conventions. -#- You should avoid functions longer 50 lines +# - Code should be clear and concise. +# - Variables inside the code should have meaningful names. +# - Every function exposed to the user should have documentation that specifies all parameters, types, input and output arguments. +# - Most people will not look at the defaults, so it is very important to nudge users to label important details of the plot. +# - Function naming should be based on some theory and naming conventions. +# - You should avoid functions longer 50 lines. diff --git a/docs/literate/tutorials/designmatrix.jl b/docs/literate/tutorials/designmatrix.jl index b6552e800..d6a34dc4b 100644 --- a/docs/literate/tutorials/designmatrix.jl +++ b/docs/literate/tutorials/designmatrix.jl @@ -11,7 +11,7 @@ using CairoMakie # Data include("../../../example_data.jl") -uf = example_data("UnfoldLinearModel") +uf = example_data("UnfoldLinearModel"); # # Plot Designmatrices diff --git a/docs/literate/tutorials/erp.jl b/docs/literate/tutorials/erp.jl index 3e2a97ebd..cd7cddb15 100644 --- a/docs/literate/tutorials/erp.jl +++ b/docs/literate/tutorials/erp.jl @@ -13,7 +13,7 @@ using CairoMakie using DataFramesMeta using UnfoldSim using UnfoldMakie -include("../../../example_data.jl") +include("../../../example_data.jl"); # Data generation From 30557112fd2af1a314f5efa3e22fe10dce04321e Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 17 Sep 2024 14:24:57 +0000 Subject: [PATCH 29/67] bug in docstrings --- src/plot_splines.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 964c5db81..184bd9ba0 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -13,6 +13,7 @@ Dashed lines shows spline knots. - `m::UnfoldModel`\\ UnfoldModel with splines. +$(_docstring(:splines)) **Return Value:** `Figure` with splines and their density for basis functions. """ plot_splines(m::UnfoldModel; kwargs...) = plot_splines(Figure(), m; kwargs...) From 15bcb062bac2bd271d728fb1b48c06fde0d0608b Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 17 Sep 2024 14:25:47 +0000 Subject: [PATCH 30/67] simplification in plot_erp --- src/plot_erp.jl | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index d3ca7c569..b21bbbe4a 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -115,30 +115,14 @@ function plot_erp!( end mapp = AlgebraOfGraphics.mapping() - #= for i in [:color, :group, :col] + + # mapping for stderrors + for i in [:color, :group, :col, :row, :layout] if (i ∈ keys(config.mapping)) tmp = getindex(config.mapping, i) - mapp = mapp * AlgebraOfGraphics.mapping(; tmp ) + mapp = mapp * AlgebraOfGraphics.mapping(; i => tmp) end - end haven't solved it yet =# - - # mapping for stderrors - if (:color ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.color) - end - if (:group ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.group) end - if (:col ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.col) - end - if (:row ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.row) - end - if (:layout ∈ keys(config.layout)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.layout) - end - # remove x / y mapping_others = deleteKeys(config.mapping, [:x, :y, :positions, :lables]) From 248c168e813889698fa07099a96634cc79865871 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 17 Sep 2024 14:27:15 +0000 Subject: [PATCH 31/67] test for issue 232 --- test/test_erp.jl | 28 ++++++++++++++++++++++++++++ test/test_splines.jl | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/test_erp.jl b/test/test_erp.jl index 6735c0aef..554e8b17d 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -132,3 +132,31 @@ end ) f end + +@testset "ERP plot: Facet sorting" begin + data, evts = UnfoldSim.predef_eeg() + + m = fit( + UnfoldModel, + [ + "car" => (@formula(0 ~ 1 + continuous), firbasis((-0.1, 1), 100)), + "face" => (@formula(0 ~ 1 + continuous), firbasis((-0.1, 1), 100)), + ], + evts, + data; + eventcolumn = :condition, + ) + eff = effects(Dict(:continuous => 75:20:300), m) + + sorting = ["face", "car"] + sorting = ["car", "face"] + + plot_erp( + eff; + mapping = (; + col = :eventname => sorter(sorting), + color = :continuous, + group = :continuous, + ), + ) +end diff --git a/test/test_splines.jl b/test/test_splines.jl index 1e2d73921..596cd5181 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -8,4 +8,4 @@ end @testset "Spline plot: two spline terms" begin plot_splines(m2) -end \ No newline at end of file +end From 667eacc26019aff380b740ba0262cc0528582a03 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 17 Sep 2024 14:29:25 +0000 Subject: [PATCH 32/67] better example2 --- test/test_erp.jl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/test_erp.jl b/test/test_erp.jl index 554e8b17d..4078b772b 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -148,15 +148,25 @@ end ) eff = effects(Dict(:continuous => 75:20:300), m) - sorting = ["face", "car"] - sorting = ["car", "face"] + sorting1 = ["face", "car"] # check + sorting2 = ["car", "face"] - plot_erp( + f = Figure() + plot_erp!(f[1, 1], + eff; + mapping = (; + col = :eventname => sorter(sorting1), + color = :continuous, + group = :continuous, + ), + ) + plot_erp!(f[2, 1], eff; mapping = (; - col = :eventname => sorter(sorting), + col = :eventname => sorter(sorting2), color = :continuous, group = :continuous, ), ) + f end From d61c72c8b91da9113f0eb65aa781978d12b6f09b Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 17 Sep 2024 19:40:52 +0000 Subject: [PATCH 33/67] buf for doctrsring --- src/docstring_template.jl | 2 ++ src/plot_splines.jl | 2 +- test/test_erp.jl | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 93572e216..1cb780dc7 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -14,6 +14,7 @@ function _docstring(cfg_symb::Symbol) :circtopos => `Topoplot.eeg_topoplot`, :topoplot => `Topoplot.eeg_topoplot`, :topoplotseries => `Topoplot.eeg_topoplot`, + :splines => `Makie.series`, ) visuallink2 = Dict( :erp => "https://docs.makie.org/stable/reference/plots/lines/", @@ -26,6 +27,7 @@ function _docstring(cfg_symb::Symbol) :circtopos => "https://makieorg.github.io/TopoPlots.jl/stable/eeg/", :topoplot => "https://makieorg.github.io/TopoPlots.jl/stable/eeg/", :topoplotseries => "https://makieorg.github.io/TopoPlots.jl/stable/eeg/", + :splines => "https://docs.makie.org/stable/reference/plots/series", ) cbarstring = (cfg_symb == :erp || cfg_symb == :butterfly) ? diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 184bd9ba0..491590eeb 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -12,8 +12,8 @@ Dashed lines shows spline knots. `Figure`, `GridLayout`, or `GridPosition` to draw the plot. - `m::UnfoldModel`\\ UnfoldModel with splines. - $(_docstring(:splines)) + **Return Value:** `Figure` with splines and their density for basis functions. """ plot_splines(m::UnfoldModel; kwargs...) = plot_splines(Figure(), m; kwargs...) diff --git a/test/test_erp.jl b/test/test_erp.jl index 4078b772b..b48a0a843 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -152,7 +152,8 @@ end sorting2 = ["car", "face"] f = Figure() - plot_erp!(f[1, 1], + plot_erp!( + f[1, 1], eff; mapping = (; col = :eventname => sorter(sorting1), @@ -160,7 +161,8 @@ end group = :continuous, ), ) - plot_erp!(f[2, 1], + plot_erp!( + f[2, 1], eff; mapping = (; col = :eventname => sorter(sorting2), From 090ccd72eb577ade26575cc7e0cac0ac30ecb661 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:33:09 +0200 Subject: [PATCH 34/67] Update src/plot_splines.jl Co-authored-by: Benedikt Ehinger --- src/plot_splines.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 491590eeb..046b1ed7f 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -3,7 +3,9 @@ using BSplineKit, Unfold plot_splines(m::UnfoldModel; kwargs...) plot_splines!(f::Union{GridPosition, GridLayout, Figure}, m::UnfoldModel; kwargs...) -Shows two subfigures. First, baseses of splines. Second, density of splines.\\ +Visualization of spline terms in an UnfoldModel. Per spline-term generates two subplots: 1) the spline basis function. 2) density of the underlying covariate. \\ + +Multiple spline terms are arranged over columns. Dashed lines shows spline knots. ## Arguments: From ecfe9658d50358b470c2af516734e26564fda2bf Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 09:41:21 +0000 Subject: [PATCH 35/67] compats --- Project.toml | 1 + docs/Project.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/Project.toml b/Project.toml index cb5cb205e..1cd814f90 100644 --- a/Project.toml +++ b/Project.toml @@ -35,6 +35,7 @@ UnfoldMakiePyMNEExt = "PyMNE" [compat] AlgebraOfGraphics = "0.7, 0.8" +BSplineKit = "0.17" CategoricalArrays = "0.10" ColorSchemes = "3" ColorTypes = "0.11" diff --git a/docs/Project.toml b/docs/Project.toml index 616490bae..ba3e4fe3f 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -25,3 +25,4 @@ XML2_jll = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" [compat] AlgebraOfGraphics = "0.7, 0.8" +BSplineKit = "0.17" From 9175a591cadeb4590594b9399153ce1dc1db9093 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 10:23:46 +0000 Subject: [PATCH 36/67] rearrangment of doc pages --- docs/literate/tutorials/splines.jl | 11 +++++++---- docs/make.jl | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl index 34e3ce2e7..5529670c0 100644 --- a/docs/literate/tutorials/splines.jl +++ b/docs/literate/tutorials/splines.jl @@ -1,6 +1,9 @@ # # [Spline plot](@id spline_vis) -# **Spline plot** (aka topography plot) is a plot type for visualisation of spline basises. +# **Spline plot** is a plot type for visualisation of terms in an UnfoldModel. +# Two subplots are generated for each spline term: 1) the basis function of the spline. 2) the density of the underlying covariate.\\ +# Multiple spline terms are arranged across columns. +# Dashed lines indicate spline knots. # # Setup # Package and data loading @@ -15,13 +18,13 @@ m1 = example_data("UnfoldLinearModelwith1Spline"); m2 = example_data("UnfoldLinearModelwith2Splines"); -# Spline plot with one spline term +# Spline plot with one spline term: plot_splines(m1) -# Spline plot with two spline terms +# Spline plot with two spline terms: plot_splines(m2) -# # Configurations of Butterfly Plot +# # Configurations of Spline plot # ```@docs # plot_splines diff --git a/docs/make.jl b/docs/make.jl index 37265bceb..b73e949d9 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -40,7 +40,7 @@ makedocs(; "Plot types" => "generated/intro/plot_types.md", "Code principles" => "generated/intro/code_principles.md", ], - "Visualization Types" => [ + "ERP Visualizations" => [ "ERP plot" => "generated/tutorials/erp.md", "Butterfly plot" => "generated/tutorials/butterfly.md", "Topoplot" => "generated/tutorials/topoplot.md", @@ -49,9 +49,11 @@ makedocs(; "ERP image" => "generated/tutorials/erpimage.md", "Channel image" => "generated/tutorials/channel_image.md", "Parallel coordinates" => "generated/tutorials/parallelcoordinates.md", + "Circular topoplots" => "generated/tutorials/circ_topo.md", + ], + "Unfold-specific Visualisations" => [ "Design matrix" => "generated/tutorials/designmatrix.md", "Spline plot" => "generated/tutorials/splines.md", - "Circular topoplots" => "generated/tutorials/circ_topo.md", ], "How To" => [ "Change colormap of Butterfly plot" => "generated/how_to/position2color.md", From 2f8ac9b21ff8ed1063cb2190d7793a654272ed43 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 10:48:27 +0000 Subject: [PATCH 37/67] supportive axes for splines --- src/plot_splines.jl | 81 ++++++++++++++++++--------------------------- src/plotconfig.jl | 2 +- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 046b1ed7f..16be36e7e 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -3,10 +3,11 @@ using BSplineKit, Unfold plot_splines(m::UnfoldModel; kwargs...) plot_splines!(f::Union{GridPosition, GridLayout, Figure}, m::UnfoldModel; kwargs...) -Visualization of spline terms in an UnfoldModel. Per spline-term generates two subplots: 1) the spline basis function. 2) density of the underlying covariate. \\ +Visualization of spline terms in an UnfoldModel. Two subplots are generated for each spline term:\\ +1) the basis function of the spline. 2) the density of the underlying covariate.\\ -Multiple spline terms are arranged over columns. -Dashed lines shows spline knots. +Multiple spline terms are arranged across columns. +Dashed lines indicate spline knots. ## Arguments: @@ -14,13 +15,30 @@ Dashed lines shows spline knots. `Figure`, `GridLayout`, or `GridPosition` to draw the plot. - `m::UnfoldModel`\\ UnfoldModel with splines. +- `spline_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of spline subplots.\\ + To see all options just type `?Axis` in REPL. +- `density_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of density subplots.\\ + To see all options just type `?Axis` in REPL. $(_docstring(:splines)) **Return Value:** `Figure` with splines and their density for basis functions. """ plot_splines(m::UnfoldModel; kwargs...) = plot_splines(Figure(), m; kwargs...) -function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; kwargs...) +function plot_splines( + f::Union{GridPosition,GridLayout,Figure}, + m::UnfoldModel; + spline_axis = (; + ylabel = "Spline value", + xlabelvisible = false, + xticklabelsvisible = false, + ylabelvisible = true, + ), + density_axis = (; xautolimitmargin = (0, 0), ylabel = "Density value"), + kwargs..., +) config = PlotConfig(:splines) config_kwargs!(config; kwargs...) ga = f[1, 1] = GridLayout() @@ -34,8 +52,6 @@ function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; spline_terms = [terms[i] for i in spl_ix] subplot_id = 1 for spline_term in spline_terms - #basises = BSplineBasis(BSplineOrder(i.order), i.breakpoints) - #knots = BSplineKit.knots(basises) x_range = range( spline_term.breakpoints[1], stop = spline_term.breakpoints[end], @@ -43,36 +59,27 @@ function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; ) basis_set = splFunction(x_range, spline_term) - ylabel_first = "Spline value" if subplot_id > 1 - config_kwargs!(config; axis = (; ylabelvisible = false)) - ylabel_first = "" + spline_axis = (; + ylabel = "Spline value", + xlabelvisible = false, + xticklabelsvisible = false, + ylabelvisible = false, + ) end - a1 = Axis( - ga[1, subplot_id]; - title = string(spline_term), - ylabel = ylabel_first, - xlabelvisible = false, - xticklabelsvisible = false, - ) + a1 = Axis(ga[1, subplot_id]; title = string(spline_term), spline_axis...) series!( x_range, basis_set', color = resample_cmap(config.visual.colormap, size(basis_set')[1]), - ) #contionus colormap used + ) # continuous color map used vlines!( spline_term.breakpoints; ymin = extrema(basis_set')[1], ymax = extrema(basis_set')[2], linestyle = :dash, ) - #scatter!(spline_term.breakpoints, [0,0,0,0,0,0,0,0]; markersize = 10, strokecolor = :tomato, strokewidth = 3) - a2 = Axis( - ga[2, subplot_id]; - xlabel = string(spline_term.term.sym), - xautolimitmargin = (0, 0), - config.axis..., - ) + a2 = Axis(ga[2, subplot_id]; xlabel = string(spline_term.term.sym), density_axis...) density!( Unfold.events(designmatrix(m))[1][:, spline_term.term.sym]; color = :transparent, @@ -82,31 +89,7 @@ function plot_splines(f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; linkxaxes!(a1, a2) subplot_id = subplot_id + 1 end - supertitle = - Label(ga[1, 1:end, Top()], spl_title, fontsize = 20, padding = (0, 0, 40, 0)) + Label(ga[1, 1:end, Top()], spl_title, (fontsize = 20), padding = (0, 0, 40, 0)) f end - -#= crange = [1, 2] # default - if isnothing(color) - color = 1 - elseif isa(color, AbstractVector) - if isa(color[1], String) - # categorical colors - un_c = unique(color) - color_ix = [findfirst(un_c .== c) for c in color] - #@assert length(un_c) == 1 "Only single color found, please don't specify color, " - if length(un_c) == 1 - @warn "Only single unique value found in the specified color vector" - color = cgrad(config.visual.colormap, 2)[color_ix] - else - color = cgrad(config.visual.colormap, length(un_c))[color_ix] - end - #crange = [1,length(unique(color))] - else - # continuous color - crange = [minimum(color), maximum(color)] - end - end - =# diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 35dfe6566..760ff2aeb 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -189,7 +189,7 @@ function PlotConfig(T::Val{:splines}) config_kwargs!( cfg; layout = (;), - axis = (; ylabel = "Density value"), + axis = (;), visual = (; colormap = :viridis), legend = (; title = "Splines", framevisible = false), ) From 42c9e289c4ffc07d091f962fe7e1b3e5470e0d96 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 12:45:28 +0000 Subject: [PATCH 38/67] more clever way to update supportive axes --- src/UnfoldMakie.jl | 1 + src/plot_splines.jl | 7 +---- src/plotconfig.jl | 72 +++++++++++++++++++++++++-------------------- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/UnfoldMakie.jl b/src/UnfoldMakie.jl index 8f64f40ae..68f1fc591 100644 --- a/src/UnfoldMakie.jl +++ b/src/UnfoldMakie.jl @@ -95,6 +95,7 @@ export plot_channelimage export plot_channelimage! export to_positions +export config_kwargs! export eeg_array_to_dataframe export eeg_topoplot_series export nonnumeric # reexport from AoG diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 16be36e7e..eb12be843 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -60,12 +60,7 @@ function plot_splines( basis_set = splFunction(x_range, spline_term) if subplot_id > 1 - spline_axis = (; - ylabel = "Spline value", - xlabelvisible = false, - xticklabelsvisible = false, - ylabelvisible = false, - ) + update_axis!(spline_axis; ylabelvisible = false) end a1 = Axis(ga[1, subplot_id]; title = string(spline_term), spline_axis...) series!( diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 760ff2aeb..02b4ff166 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -52,38 +52,6 @@ function PlotConfig()# defaults ) end -""" - config_kwargs!(cfg::PlotConfig; kwargs...) -Takes named tuple of `Key => NamedTuple` as kwargs and merges the fields with the defaults. -""" -function config_kwargs!(cfg::PlotConfig; kwargs...) - - is_namedtuple = [isa(t, NamedTuple) for t in values(kwargs)] - @assert( - all(is_namedtuple), - """ Keyword argument specification (kwargs...). Specified config groups must be from `NamedTuple`, but $(keys(kwargs)[.!is_namedtuple]) was not. - - Maybe you forgot the semicolon (;) at the beginning of your specification? Compare these strings: - - plot_example(...; layout = (; use_colorbar = true)) - - plot_example(...; layout = (use_colorbar = true)) - - The first is correct and creates a `NamedTuple` as needed. The second is incorrect and its call is ignored.""" - ) - list = fieldnames(PlotConfig) #[:layout, :visual, :mapping, :legend, :colorbar, :axis] - - keyList = collect(keys(kwargs)) - :extra ∈ keyList ? - @warn( - "Extra is deprecated in 0.4, and extra keyword arguments must be used directly as keyword arguments." - ) : "" - applyTo = keyList[in.(keyList, Ref(list))] - for k ∈ applyTo - setfield!(cfg, k, merge(getfield(cfg, k), kwargs[k])) - end -end - PlotConfig(T::Symbol) = PlotConfig(Val{T}()) @@ -334,3 +302,43 @@ function resolve_mappings(plot_data, mapping_data) # check mapping_data in PlotC end return (; mapping_dict...) end + +""" + config_kwargs!(cfg::PlotConfig; kwargs...) +Takes named tuple of `Key => NamedTuple` as kwargs and merges the fields with the defaults. +""" +function config_kwargs!(cfg::PlotConfig; kwargs...) + + is_namedtuple = [isa(t, NamedTuple) for t in values(kwargs)] + @assert( + all(is_namedtuple), + """ Keyword argument specification (kwargs...). Specified config groups must be from `NamedTuple`, but $(keys(kwargs)[.!is_namedtuple]) was not. + + Maybe you forgot the semicolon (;) at the beginning of your specification? Compare these strings: + + plot_example(...; layout = (; use_colorbar = true)) + + plot_example(...; layout = (use_colorbar = true)) + + The first is correct and creates a `NamedTuple` as needed. The second is incorrect and its call is ignored.""" + ) + field_list = fieldnames(PlotConfig) #[:layout, :visual, :mapping, :legend, :colorbar, :axis] + key_list = collect(keys(kwargs)) + :extra ∈ key_list ? + @warn( + "Extra is deprecated in 0.4, and extra keyword arguments must be used directly as keyword arguments." + ) : "" + apply_to = key_list[in.(key_list, Ref(field_list))] + for k ∈ apply_to + setfield!(cfg, k, merge(getfield(cfg, k), kwargs[k])) + end +end + +""" + update_axis(support_axis::NamedTuple; kwargs...) +Update values of `NamedTuple{key = value}`\\ +Used for supportive axes to make users be able to flexibly change them. +""" +function update_axis!(support_axis::NamedTuple; kwargs...) + return (; support_axis..., kwargs...) +end From 656de32e2a181d8a10cb9fcc02c9b9ebbe77552a Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 12:56:21 +0000 Subject: [PATCH 39/67] same with superlabel --- src/plot_splines.jl | 7 +++++-- src/plotconfig.jl | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index eb12be843..594f630a3 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -21,6 +21,9 @@ Dashed lines indicate spline knots. - `density_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of density subplots.\\ To see all options just type `?Axis` in REPL. +- `superlabel_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the Label on the top of the plot.\\ + To see all options just type `?Label` in REPL. $(_docstring(:splines)) **Return Value:** `Figure` with splines and their density for basis functions. @@ -37,6 +40,7 @@ function plot_splines( ylabelvisible = true, ), density_axis = (; xautolimitmargin = (0, 0), ylabel = "Density value"), + superlabel_axis = (; (fontsize = 20), padding = (0, 0, 40, 0)), kwargs..., ) config = PlotConfig(:splines) @@ -84,7 +88,6 @@ function plot_splines( linkxaxes!(a1, a2) subplot_id = subplot_id + 1 end - supertitle = - Label(ga[1, 1:end, Top()], spl_title, (fontsize = 20), padding = (0, 0, 40, 0)) + Label(ga[1, 1:end, Top()], spl_title; superlabel_axis...) f end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 02b4ff166..9e6826d00 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -305,7 +305,7 @@ end """ config_kwargs!(cfg::PlotConfig; kwargs...) -Takes named tuple of `Key => NamedTuple` as kwargs and merges the fields with the defaults. +Takes NamedTuple of `Key => NamedTuple` as kwargs and merges the fields with the defaults. """ function config_kwargs!(cfg::PlotConfig; kwargs...) From a5df6c44dfb59c70cb35f6db3f55cb26b3d9cd3c Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 13:51:10 +0000 Subject: [PATCH 40/67] now is correct --- docs/literate/tutorials/splines.jl | 2 +- src/UnfoldMakie.jl | 4 ++- src/plot_splines.jl | 40 ++++++++++++++++++++---------- src/plotconfig.jl | 7 +++--- test/test_splines.jl | 12 +++++++++ 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl index 5529670c0..1e776053d 100644 --- a/docs/literate/tutorials/splines.jl +++ b/docs/literate/tutorials/splines.jl @@ -1,6 +1,6 @@ # # [Spline plot](@id spline_vis) # **Spline plot** is a plot type for visualisation of terms in an UnfoldModel. -# Two subplots are generated for each spline term: 1) the basis function of the spline. 2) the density of the underlying covariate.\\ +# Two subplots are generated for each spline term: 1) the basis function of the spline; 2) the density of the underlying covariate.\\ # Multiple spline terms are arranged across columns. # Dashed lines indicate spline knots. diff --git a/src/UnfoldMakie.jl b/src/UnfoldMakie.jl index 68f1fc591..4f1003120 100644 --- a/src/UnfoldMakie.jl +++ b/src/UnfoldMakie.jl @@ -95,8 +95,10 @@ export plot_channelimage export plot_channelimage! export to_positions -export config_kwargs! export eeg_array_to_dataframe export eeg_topoplot_series export nonnumeric # reexport from AoG + +export config_kwargs! +export update_axis! end diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 594f630a3..c157f18c9 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -4,7 +4,7 @@ using BSplineKit, Unfold plot_splines!(f::Union{GridPosition, GridLayout, Figure}, m::UnfoldModel; kwargs...) Visualization of spline terms in an UnfoldModel. Two subplots are generated for each spline term:\\ -1) the basis function of the spline. 2) the density of the underlying covariate.\\ +1) the basis function of the spline; 2) the density of the underlying covariate.\\ Multiple spline terms are arranged across columns. Dashed lines indicate spline knots. @@ -15,13 +15,13 @@ Dashed lines indicate spline knots. `Figure`, `GridLayout`, or `GridPosition` to draw the plot. - `m::UnfoldModel`\\ UnfoldModel with splines. -- `spline_axis::NamedTuple = (;)`\\ +- `spline_kwargs::NamedTuple = (;)`\\ Here you can flexibly change configurations of spline subplots.\\ To see all options just type `?Axis` in REPL. -- `density_axis::NamedTuple = (;)`\\ +- `density_kwargs::NamedTuple = (;)`\\ Here you can flexibly change configurations of density subplots.\\ To see all options just type `?Axis` in REPL. -- `superlabel_axis::NamedTuple = (;)`\\ +- `superlabel_kwargs::NamedTuple = (;)`\\ Here you can flexibly change configurations of the Label on the top of the plot.\\ To see all options just type `?Label` in REPL. $(_docstring(:splines)) @@ -33,18 +33,16 @@ plot_splines(m::UnfoldModel; kwargs...) = plot_splines(Figure(), m; kwargs...) function plot_splines( f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; - spline_axis = (; - ylabel = "Spline value", - xlabelvisible = false, - xticklabelsvisible = false, - ylabelvisible = true, - ), - density_axis = (; xautolimitmargin = (0, 0), ylabel = "Density value"), - superlabel_axis = (; (fontsize = 20), padding = (0, 0, 40, 0)), + spline_kwargs = (;), + density_kwargs = (;), + superlabel_kwargs = (;), kwargs..., ) config = PlotConfig(:splines) config_kwargs!(config; kwargs...) + spline_axis, density_axis, superlabel_axis = + supportive_axis_managment(spline_kwargs, density_kwargs, superlabel_kwargs) + ga = f[1, 1] = GridLayout() terms = Unfold.formulas(m)[1].rhs.terms @@ -64,7 +62,7 @@ function plot_splines( basis_set = splFunction(x_range, spline_term) if subplot_id > 1 - update_axis!(spline_axis; ylabelvisible = false) + spline_axis = update_axis!(spline_axis; ylabelvisible = false) end a1 = Axis(ga[1, subplot_id]; title = string(spline_term), spline_axis...) series!( @@ -91,3 +89,19 @@ function plot_splines( Label(ga[1, 1:end, Top()], spl_title; superlabel_axis...) f end + +function supportive_axis_managment(spline_kwargs, density_kwargs, superlabel_kwargs) + spline_axis = (; + ylabel = "Spline value", + xlabelvisible = false, + xticklabelsvisible = false, + ylabelvisible = true, + ) + density_axis = (; xautolimitmargin = (0, 0), ylabel = "Density value") + superlabel_axis = (; fontsize = 20, padding = (0, 0, 40, 0)) + + spline_axis = update_axis!(spline_axis; spline_kwargs...) + density_axis = update_axis!(density_axis; density_kwargs...) + superlabel_axis = update_axis!(superlabel_axis; superlabel_kwargs...) + return spline_axis, density_axis, superlabel_axis +end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 9e6826d00..7aad74d23 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -335,10 +335,11 @@ function config_kwargs!(cfg::PlotConfig; kwargs...) end """ - update_axis(support_axis::NamedTuple; kwargs...) -Update values of `NamedTuple{key = value}`\\ + update_axis!(support_axis::NamedTuple; kwargs...) +Update values of `NamedTuple{key = value}`.\\ Used for supportive axes to make users be able to flexibly change them. """ function update_axis!(support_axis::NamedTuple; kwargs...) - return (; support_axis..., kwargs...) + support_axis = (; support_axis..., kwargs...) + return support_axis end diff --git a/test/test_splines.jl b/test/test_splines.jl index 596cd5181..ecab49e28 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -9,3 +9,15 @@ end @testset "Spline plot: two spline terms" begin plot_splines(m2) end + +@testset "Spline plot: superlabel_axis check" begin + plot_splines(m2; superlabel_kwargs = (; fontsize = 60)) +end + +@testset "Spline plot: spline_axis check" begin + plot_splines(m2; spline_kwargs = (; ylabel = "test")) +end + +@testset "Spline plot: density_axis check" begin + plot_splines(m2, density_kwargs = (; ylabel = "test")) +end From 8d674e50542c047c1290432b803bc81d280ed80c Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 14:20:06 +0000 Subject: [PATCH 41/67] issue 172 and no_spline test --- src/plot_splines.jl | 5 +++-- src/plot_topoplotseries.jl | 19 +++++++++---------- test/test_splines.jl | 13 +++++++++++++ test/test_toposeries2.jl | 17 ++++++++++++----- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index c157f18c9..aeec82fde 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -41,7 +41,7 @@ function plot_splines( config = PlotConfig(:splines) config_kwargs!(config; kwargs...) spline_axis, density_axis, superlabel_axis = - supportive_axis_managment(spline_kwargs, density_kwargs, superlabel_kwargs) + supportive_axes_management(spline_kwargs, density_kwargs, superlabel_kwargs) ga = f[1, 1] = GridLayout() @@ -50,6 +50,7 @@ function plot_splines( splFunction = Base.get_extension(Unfold, :UnfoldBSplineKitExt).splFunction spl_ix = findall(isa.(terms, Unfold.AbstractSplineTerm)) + @assert !isempty(spl_ix) "No spline term is found in UnfoldModel. Did you forget to provide spline a formula?" spline_terms = [terms[i] for i in spl_ix] subplot_id = 1 @@ -90,7 +91,7 @@ function plot_splines( f end -function supportive_axis_managment(spline_kwargs, density_kwargs, superlabel_kwargs) +function supportive_axes_management(spline_kwargs, density_kwargs, superlabel_kwargs) spline_axis = (; ylabel = "Spline value", xlabelvisible = false, diff --git a/src/plot_topoplotseries.jl b/src/plot_topoplotseries.jl index ea2335e7d..cf6a89419 100644 --- a/src/plot_topoplotseries.jl +++ b/src/plot_topoplotseries.jl @@ -45,6 +45,9 @@ Multiple miniature topoplots in regular distances. - `visual.colorrange::2-element Vector{Int64}`, `colorbar.colorrange::2-element Vector{Int64}`\\ First is resposnible for colorrange in topoplots, second - in colorbars. Ideally they should be the same. + +Code description: +- $(_docstring(:topoplotseries)) **Return Value:** `Figure` displaying the Topoplot series. @@ -83,7 +86,7 @@ function plot_topoplotseries!( cat_or_cont_columns = eltype(data_copy[!, config.mapping.col]) <: Number ? "cont" : "cat" if cat_or_cont_columns == "cat" - # overwrite Time windows [s] default if categorical + # overwrite 'Time windows [s]' default if categorical n_topoplots = number_of_topoplots(data_copy; bin_width, bin_num, bins = 0, config.mapping) ix = @@ -132,15 +135,11 @@ function plot_topoplotseries!( config.visual..., positions, ) - if (config.colorbar.colorrange !== nothing) - config_kwargs!(config) - else - config_kwargs!( - config, - visual = (; colorrange = colorrange), - colorbar = (; colorrange = colorrange), - ) - end + config_kwargs!( + config, + visual = (; colorrange = colorrange), + colorbar = (; colorrange = colorrange), + ) if !config.layout.use_colorbar config_kwargs!(config, layout = (; use_colorbar = false, show_legend = false)) end diff --git a/test/test_splines.jl b/test/test_splines.jl index ecab49e28..246932a36 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -1,7 +1,20 @@ using BSplineKit, Unfold +m0 = example_data("UnfoldLinearModel") m1 = example_data("UnfoldLinearModelwith1Spline") m2 = example_data("UnfoldLinearModelwith2Splines") +@testset "Spline plot: no splines" begin + err1 = nothing + t() = error(plot_splines(m0)) + try + t() + catch err1 + end + @test err1 == AssertionError( + "No spline term is found in UnfoldModel. Did you forget to provide spline a formula?", + ) +end + @testset "Spline plot: basic" begin plot_splines(m1) end diff --git a/test/test_toposeries2.jl b/test/test_toposeries2.jl index f15d5597f..e6b84d4d2 100644 --- a/test/test_toposeries2.jl +++ b/test/test_toposeries2.jl @@ -29,7 +29,6 @@ end ) end - @testset "error checking: bin_width and bin_num specified" begin err1 = nothing t() = error(plot_topoplotseries(df; bin_width = 80, bin_num = 5, positions = positions)) @@ -99,17 +98,19 @@ end mapping = (; col = :condition), ) end - -#= @testset "4 condtions in rows" begin # TBD +#= +@testset "4 condtions in rows" begin # TBD df = UnfoldMakie.eeg_array_to_dataframe(dat[:, 1:4, 1], string.(1:length(positions))) df.condition = repeat(["A", "B", "C", "D"], size(df, 1) ÷ 4) plot_topoplotseries( df; + bin_num = 3, positions = positions, mapping = (; row = :condition), ) -end =# +end +=# @testset "topoplot axes configuration" begin # TBD df = UnfoldMakie.eeg_array_to_dataframe(dat[:, 1:4, 1], string.(1:length(positions))) @@ -129,7 +130,6 @@ end =# ) end - @testset "change xlabel" begin df = UnfoldMakie.eeg_array_to_dataframe(dat[:, 1:2, 1], string.(1:length(positions))) df.condition = repeat(["A", "B"], size(df, 1) ÷ 2) @@ -177,3 +177,10 @@ end interactive_scatter = obs_tuple, ) end +#= +@testset "interactive data in eeg_array_to_dataframe" begin + data_obs3 = Observable(UnfoldMakie.eeg_array_to_dataframe(rand(10, 20))) + plot_topoplotseries!(Figure(), data_obs3; bin_num = 5, positions = rand(Point2f, 10)) + data_obs3[] = UnfoldMakie.eeg_array_to_dataframe(rand(10, 20)) +end +=# From 5ed10d1007e65f5c9c9fe1a8e5e45d95a0258078 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 14:22:30 +0000 Subject: [PATCH 42/67] compats --- Project.toml | 2 +- docs/Project.toml | 2 +- test/Project.toml | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 1cd814f90..991bfaba1 100644 --- a/Project.toml +++ b/Project.toml @@ -35,7 +35,7 @@ UnfoldMakiePyMNEExt = "PyMNE" [compat] AlgebraOfGraphics = "0.7, 0.8" -BSplineKit = "0.17" +BSplineKit = "0.16, 0.17" CategoricalArrays = "0.10" ColorSchemes = "3" ColorTypes = "0.11" diff --git a/docs/Project.toml b/docs/Project.toml index ba3e4fe3f..b07f03b59 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -25,4 +25,4 @@ XML2_jll = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" [compat] AlgebraOfGraphics = "0.7, 0.8" -BSplineKit = "0.17" +BSplineKit = "0.16, 0.17" diff --git a/test/Project.toml b/test/Project.toml index ff865372a..181e9f34a 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -11,3 +11,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TopoPlots = "2bdbdf9c-dbd8-403f-947b-1a4e0dd41a7a" Unfold = "181c99d8-e21b-4ff3-b70b-c233eddec679" UnfoldSim = "ed8ae6d2-84d3-44c6-ab46-0baf21700804" + +[compat] +AlgebraOfGraphics = "0.7, 0.8" +BSplineKit = "0.16, 0.17" From d7a7d9036227655070d9e6ff34003b74d6644d23 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 18 Sep 2024 14:25:00 +0000 Subject: [PATCH 43/67] renaming --- src/plot_splines.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index aeec82fde..b6063296b 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -40,7 +40,7 @@ function plot_splines( ) config = PlotConfig(:splines) config_kwargs!(config; kwargs...) - spline_axis, density_axis, superlabel_axis = + spline_axis, density_axis, superlabel_config = supportive_axes_management(spline_kwargs, density_kwargs, superlabel_kwargs) ga = f[1, 1] = GridLayout() @@ -87,7 +87,7 @@ function plot_splines( linkxaxes!(a1, a2) subplot_id = subplot_id + 1 end - Label(ga[1, 1:end, Top()], spl_title; superlabel_axis...) + Label(ga[1, 1:end, Top()], spl_title; superlabel_config...) f end @@ -99,10 +99,10 @@ function supportive_axes_management(spline_kwargs, density_kwargs, superlabel_kw ylabelvisible = true, ) density_axis = (; xautolimitmargin = (0, 0), ylabel = "Density value") - superlabel_axis = (; fontsize = 20, padding = (0, 0, 40, 0)) + superlabel_config = (; fontsize = 20, padding = (0, 0, 40, 0)) spline_axis = update_axis!(spline_axis; spline_kwargs...) density_axis = update_axis!(density_axis; density_kwargs...) - superlabel_axis = update_axis!(superlabel_axis; superlabel_kwargs...) - return spline_axis, density_axis, superlabel_axis + superlabel_config = update_axis!(superlabel_config; superlabel_kwargs...) + return spline_axis, density_axis, superlabel_config end From 3c6c7c4ea8db2a25edb2bb6f7c12553576a8417b Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:00:27 +0000 Subject: [PATCH 44/67] Update src/plot_splines.jl Co-authored-by: Benedikt Ehinger --- src/plot_splines.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index b6063296b..bac65de93 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -50,7 +50,7 @@ function plot_splines( splFunction = Base.get_extension(Unfold, :UnfoldBSplineKitExt).splFunction spl_ix = findall(isa.(terms, Unfold.AbstractSplineTerm)) - @assert !isempty(spl_ix) "No spline term is found in UnfoldModel. Did you forget to provide spline a formula?" + @assert !isempty(spl_ix) "No spline term is found in UnfoldModel. Does your UnfoldModel really have a `spl(...)` or other `AbstractSplineTerm`?" spline_terms = [terms[i] for i in spl_ix] subplot_id = 1 From c7de87cbfe8c810d8eea699737abd2dfaf402bb5 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 17:15:40 +0000 Subject: [PATCH 45/67] after comments --- src/UnfoldMakie.jl | 2 -- src/plot_erp.jl | 34 ---------------------------------- src/plot_splines.jl | 31 ++++++++++++++++--------------- src/plotconfig.jl | 2 +- test/test_splines.jl | 6 +++--- 5 files changed, 20 insertions(+), 55 deletions(-) diff --git a/src/UnfoldMakie.jl b/src/UnfoldMakie.jl index 4f1003120..6dc2213c1 100644 --- a/src/UnfoldMakie.jl +++ b/src/UnfoldMakie.jl @@ -99,6 +99,4 @@ export eeg_array_to_dataframe export eeg_topoplot_series export nonnumeric # reexport from AoG -export config_kwargs! -export update_axis! end diff --git a/src/plot_erp.jl b/src/plot_erp.jl index b21bbbe4a..0a09148a0 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -85,10 +85,6 @@ function plot_erp!( plot_data.group = plot_data.group .|> a -> isnothing(a) ? :fixef : a end - if "group" ∈ names(plot_data) - plot_data.group = plot_data.group .|> a -> isnothing(a) ? :fixef : a - end - # automatically convert col & group to nonnumeric if ( :col ∈ keys(config.mapping) && @@ -185,36 +181,6 @@ function eeg_head_matrix(positions, center, radius) ) end -# topopositions_to_color = colors? -function topoplot_legend(axis, topomarkersize, unique_val, colors, all_positions) - all_positions = unique(all_positions) - - topo_matrix = eeg_head_matrix(all_positions, (0.5, 0.5), 0.5) - - un = unique(unique_val) - special_colors = - ColorScheme(vcat(RGB(1, 1, 1.0), colors[map(x -> findfirst(x .== un), unique_val)])) - - xlims!(low = -0.2, high = 1.2) - ylims!(low = -0.2, high = 1.2) - topoplot = eeg_topoplot!( - axis, - 1:length(all_positions), # go from 1:npos - string.(1:length(all_positions)); - positions = all_positions, - interpolation = NullInterpolator(), # inteprolator that returns only 0, which is put to white in the special_colorsmap - colorrange = (0, length(all_positions)), # add the 0 for the white-first color - colormap = special_colors, - head = (color = :black, linewidth = 1, model = topo_matrix), - label_scatter = (markersize = topomarkersize, strokewidth = 0.5), - ) - - hidedecorations!(current_axis()) - hidespines!(current_axis()) - - return topoplot -end - function add_significance(plot_data, significance, config) p = deepcopy(significance) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index bac65de93..77f24249e 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -15,13 +15,13 @@ Dashed lines indicate spline knots. `Figure`, `GridLayout`, or `GridPosition` to draw the plot. - `m::UnfoldModel`\\ UnfoldModel with splines. -- `spline_kwargs::NamedTuple = (;)`\\ +- `spline_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of spline subplots.\\ To see all options just type `?Axis` in REPL. -- `density_kwargs::NamedTuple = (;)`\\ +- `density_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of density subplots.\\ To see all options just type `?Axis` in REPL. -- `superlabel_kwargs::NamedTuple = (;)`\\ +- `superlabel_config::NamedTuple = (;)`\\ Here you can flexibly change configurations of the Label on the top of the plot.\\ To see all options just type `?Label` in REPL. $(_docstring(:splines)) @@ -33,15 +33,15 @@ plot_splines(m::UnfoldModel; kwargs...) = plot_splines(Figure(), m; kwargs...) function plot_splines( f::Union{GridPosition,GridLayout,Figure}, m::UnfoldModel; - spline_kwargs = (;), - density_kwargs = (;), - superlabel_kwargs = (;), + spline_axis = (;), + density_axis = (;), + superlabel_config = (;), kwargs..., ) config = PlotConfig(:splines) config_kwargs!(config; kwargs...) spline_axis, density_axis, superlabel_config = - supportive_axes_management(spline_kwargs, density_kwargs, superlabel_kwargs) + supportive_axes_management(spline_axis, density_axis, superlabel_config) ga = f[1, 1] = GridLayout() @@ -63,7 +63,8 @@ function plot_splines( basis_set = splFunction(x_range, spline_term) if subplot_id > 1 - spline_axis = update_axis!(spline_axis; ylabelvisible = false) + spline_axis = update_axis(spline_axis; ylabelvisible = false) + density_axis = update_axis(density_axis; ylabelvisible = false) end a1 = Axis(ga[1, subplot_id]; title = string(spline_term), spline_axis...) series!( @@ -91,18 +92,18 @@ function plot_splines( f end -function supportive_axes_management(spline_kwargs, density_kwargs, superlabel_kwargs) - spline_axis = (; +function supportive_axes_management(spline_axis, density_axis, superlabel_config) + spline_default = (; ylabel = "Spline value", xlabelvisible = false, xticklabelsvisible = false, ylabelvisible = true, ) - density_axis = (; xautolimitmargin = (0, 0), ylabel = "Density value") - superlabel_config = (; fontsize = 20, padding = (0, 0, 40, 0)) + density_default = (; xautolimitmargin = (0, 0), ylabel = "Density value") + superlabel_default = (; fontsize = 20, padding = (0, 0, 40, 0)) - spline_axis = update_axis!(spline_axis; spline_kwargs...) - density_axis = update_axis!(density_axis; density_kwargs...) - superlabel_config = update_axis!(superlabel_config; superlabel_kwargs...) + spline_axis = update_axis(spline_default; spline_axis...) + density_axis = update_axis(density_default; density_axis...) + superlabel_config = update_axis(superlabel_default; superlabel_config...) return spline_axis, density_axis, superlabel_config end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 7aad74d23..e786dae54 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -339,7 +339,7 @@ end Update values of `NamedTuple{key = value}`.\\ Used for supportive axes to make users be able to flexibly change them. """ -function update_axis!(support_axis::NamedTuple; kwargs...) +function update_axis(support_axis::NamedTuple; kwargs...) support_axis = (; support_axis..., kwargs...) return support_axis end diff --git a/test/test_splines.jl b/test/test_splines.jl index 246932a36..5ec68bac7 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -24,13 +24,13 @@ end end @testset "Spline plot: superlabel_axis check" begin - plot_splines(m2; superlabel_kwargs = (; fontsize = 60)) + plot_splines(m2; superlabel_config = (; fontsize = 60)) end @testset "Spline plot: spline_axis check" begin - plot_splines(m2; spline_kwargs = (; ylabel = "test")) + plot_splines(m2; spline_axis = (; ylabel = "test")) end @testset "Spline plot: density_axis check" begin - plot_splines(m2, density_kwargs = (; ylabel = "test")) + plot_splines(m2, density_axis = (; ylabel = "test")) end From da27b27a19dd1020e112f2f38fab1ffa8bf4cccd Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 17:43:58 +0000 Subject: [PATCH 46/67] we accidently lost colorbars --- src/plot_topoplot.jl | 4 +++- src/plot_topoplotseries.jl | 17 ++++++++++++----- src/plotconfig.jl | 2 +- test/test_toposeries1.jl | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/plot_topoplot.jl b/src/plot_topoplot.jl index 0747b2d61..5134c9827 100644 --- a/src/plot_topoplot.jl +++ b/src/plot_topoplot.jl @@ -42,7 +42,9 @@ function plot_topoplot!( end positions = get_topo_positions(; positions = positions, labels = labels) eeg_topoplot!(axis, data, labels; positions, config.visual...) - + if config.layout.use_colorbar == true + Colorbar(f[1, 2]; colormap = config.visual.colormap, config.colorbar...) + end clims = (min(data...), max(data...)) if clims[1] ≈ clims[2] @warn """The min and max of the value represented by the color are the same, it seems that the data values are identical. diff --git a/src/plot_topoplotseries.jl b/src/plot_topoplotseries.jl index cf6a89419..0c75455e5 100644 --- a/src/plot_topoplotseries.jl +++ b/src/plot_topoplotseries.jl @@ -42,8 +42,8 @@ Multiple miniature topoplots in regular distances. `mapping.col` - specify x-value, can be any continuous or categorical variable.\\ `mapping.row` - specify y-value, can be any continuous or categorical variable (not implemented yet).\\ `mapping.layout` - arranges topoplots by rows when equals `:time`.\\ -- `visual.colorrange::2-element Vector{Int64}`, `colorbar.colorrange::2-element Vector{Int64}`\\ - First is resposnible for colorrange in topoplots, second - in colorbars. Ideally they should be the same. +- `visual..colorrange::2-element Vector{Int64}`\\ + Resposnible for colorrange in topoplots and in colorbar. Code description: @@ -140,13 +140,20 @@ function plot_topoplotseries!( visual = (; colorrange = colorrange), colorbar = (; colorrange = colorrange), ) - if !config.layout.use_colorbar - config_kwargs!(config, layout = (; use_colorbar = false, show_legend = false)) - end + + config_kwargs!( + config, + visual = (; colorrange = colorrange), + colorbar = (; colorrange = colorrange), + ) + ax = Axis( f[1, 1]; (p for p in pairs(config.axis) if p[1] != :xlim_topo && p[1] != :ylim_topo)..., ) + if config.layout.use_colorbar == true + Colorbar(f[1, 2]; colormap = config.visual.colormap, config.colorbar...) + end apply_layout_settings!(config; fig = f, ax = ax) return f end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index e786dae54..b8dc8e827 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -28,7 +28,7 @@ function PlotConfig()# defaults (;), # axis (; # layout show_legend = true, - use_colorbar = false, # ideally should be deleted + use_colorbar = true, # ideally should be deleted ), (#maping x = (:time,), diff --git a/test/test_toposeries1.jl b/test/test_toposeries1.jl index 775ee60d2..cdf981ef9 100644 --- a/test/test_toposeries1.jl +++ b/test/test_toposeries1.jl @@ -145,7 +145,7 @@ end df; bin_width, positions = positions, - colorbar = (; colorrange = (-3, 3)), + visual = (; colorrange = (-3, 3)), ) end From ca787bd243095f0540f607fd105ac37de3a17ba0 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 19:03:18 +0000 Subject: [PATCH 47/67] issue 239 --- docs/literate/how_to/hide_deco.jl | 7 +- docs/literate/how_to/mult_vis_in_fig.jl | 3 +- docs/literate/tutorials/butterfly.jl | 7 +- src/plot_butterfly.jl | 105 ++++++++++++++++++------ src/plot_erp.jl | 24 ------ test/test_butterfly.jl | 10 +-- test/test_complexplots.jl | 3 +- 7 files changed, 93 insertions(+), 66 deletions(-) diff --git a/docs/literate/how_to/hide_deco.jl b/docs/literate/how_to/hide_deco.jl index 99d8c67d8..af9600a58 100644 --- a/docs/literate/how_to/hide_deco.jl +++ b/docs/literate/how_to/hide_deco.jl @@ -32,8 +32,7 @@ plot_butterfly!( data; positions = pos, topomarkersize = 10, - topoheight = 0.4, - topowidth = 0.4, + topo_axis = (; height = Relative(0.4), width = Relative(0.4)), axis = (; title = "With decorations"), ) plot_butterfly!( @@ -41,8 +40,8 @@ plot_butterfly!( data; positions = pos, topomarkersize = 10, - topoheight = 0.4, - topowidth = 0.4, + topo_axis = (; height = Relative(0.4), width = Relative(0.4)), + opoheight = 0.4, axis = (; title = "Without decorations"), layout = (; hidedecorations = (:label => true, :ticks => true, :ticklabels => true)), ) diff --git a/docs/literate/how_to/mult_vis_in_fig.jl b/docs/literate/how_to/mult_vis_in_fig.jl index b28782598..e409b21b5 100644 --- a/docs/literate/how_to/mult_vis_in_fig.jl +++ b/docs/literate/how_to/mult_vis_in_fig.jl @@ -148,8 +148,7 @@ plot_butterfly!( d_topo; positions = pos, topomarkersize = 10, - topoheight = 0.4, - topowidth = 0.4, + topo_axis = (; height = Relative(0.4), width = Relative(0.4)), ) hlines!(0, color = :gray, linewidth = 1) vlines!(0, color = :gray, linewidth = 1) diff --git a/docs/literate/tutorials/butterfly.jl b/docs/literate/tutorials/butterfly.jl index edf54b478..043170874 100644 --- a/docs/literate/tutorials/butterfly.jl +++ b/docs/literate/tutorials/butterfly.jl @@ -38,7 +38,12 @@ plot_butterfly(df; positions = pos) # You want to change size of topomarkers and size of topoplot: -plot_butterfly(df; positions = pos, topomarkersize = 10, topoheight = 0.4, topowidth = 0.4) +plot_butterfly( + df; + positions = pos, + topomarkersize = 10, + topo_axis = (; height = Relative(0.4), width = Relative(0.4)), +) # You want to add vline and hline: diff --git a/src/plot_butterfly.jl b/src/plot_butterfly.jl index 6346eac0b..e26e6625d 100644 --- a/src/plot_butterfly.jl +++ b/src/plot_butterfly.jl @@ -26,12 +26,17 @@ Plot a Butterfly plot. Show an inlay topoplot with corresponding electrodes. Requires `positions`. - `topomarkersize::Real = 10` \\ Change the size of the electrode markers in topoplot. -- `topowidth::Real = 0.25` \\ - Change the width of inlay topoplot. -- `topoheight::Real = 0.25` \\ - Change the height of inlay topoplot. - `topopositions_to_color::x -> pos_to_color_RomaO(x)`\\ Change the line colors. +- `topo_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the topoplot axis.\\ + To see all options just type `?Axis` in REPL. +- `topo_axis.width::Real = 0.25` \\ + Change the width of inlay topoplot. +- `topo_axis.height::Real = 0.25` \\ + Change the height of inlay topoplot. +- `mapping = (;)`\\ + For highlighting specific channels. **Return Value:** `Figure` displaying Butterfly plot. @@ -48,13 +53,9 @@ function plot_butterfly!( labels = nothing, topolegend = true, topomarkersize = 10, - topowidth = 0.35, - topoheight = 0.35, - topohalign = 0.05, - topovalign = 0.95, - topoaspect = 1, topopositions_to_color = x -> pos_to_color_RomaO(x), - mapping = (;), + topo_axis = (;), + mapping = (;), # WTf?? kwargs..., ) @@ -93,6 +94,7 @@ function plot_butterfly!( colors = get_topo_color(all_positions, topopositions_to_color) end end + # Categorical mapping # convert color column into string to prevent wrong grouping if (:group ∈ keys(config.mapping)) @@ -111,15 +113,12 @@ function plot_butterfly!( end mapp = AlgebraOfGraphics.mapping() - - if (:color ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.color) - end - - if (:group ∈ keys(config.mapping)) - mapp = mapp * AlgebraOfGraphics.mapping(; config.mapping.group) + for i in [:color, :group] + if (i ∈ keys(config.mapping)) + tmp = getindex(config.mapping, i) + mapp = mapp * AlgebraOfGraphics.mapping(; i => tmp) + end end - # remove x / y mapping_others = deleteKeys(config.mapping, [:x, :y, :positions, :lables]) xy_mapp = @@ -131,25 +130,24 @@ function plot_butterfly!( f_grid = f[1, 1] if (topolegend) - topoAxis = Axis( - f_grid, - width = Relative(topowidth), - height = Relative(topoheight), - halign = topohalign, - valign = topovalign, - aspect = topoaspect, + topo_default = (; + width = Relative(0.35), + height = Relative(0.35), + halign = 0.05, + valign = 0.95, + aspect = 1, ) + topo_axis = update_axis(topo_default; topo_axis...) ix = unique(i -> plot_data[:, config.mapping.group[1]][i], 1:size(plot_data, 1)) topoplot_legend( - topoAxis, + Axis(f_grid; topo_axis...), topomarkersize, plot_data[ix, config.mapping.color[1]], colors, all_positions, ) end - if isnothing(colors) drawing = draw!(f_grid, plot_equation; axis = config.axis) else @@ -163,3 +161,56 @@ function plot_butterfly!( apply_layout_settings!(config; fig = f, ax = drawing, drawing = drawing) return f end + + +# topopositions_to_color = colors? +function topoplot_legend(axis, topomarkersize, unique_val, colors, all_positions) + all_positions = unique(all_positions) + topo_matrix = eeg_head_matrix(all_positions, (0.5, 0.5), 0.5) + + un = unique(unique_val) + special_colors = + ColorScheme(vcat(RGB(1, 1, 1.0), colors[map(x -> findfirst(x .== un), unique_val)])) + + xlims!(low = -0.2, high = 1.2) + ylims!(low = -0.2, high = 1.2) + + topoplot = eeg_topoplot!( + axis, + 1:length(all_positions), # go from 1:npos + string.(1:length(all_positions)); + positions = all_positions, + interpolation = NullInterpolator(), # inteprolator that returns only 0, which is put to white in the special_colorsmap + colorrange = (0, length(all_positions)), # add the 0 for the white-first color + colormap = special_colors, + head = (color = :black, linewidth = 1, model = topo_matrix), + label_scatter = (markersize = topomarkersize, strokewidth = 0.5), + ) + hidespines!(axis) + hidedecorations!(axis) + return topoplot +end + +function eeg_head_matrix(positions, center, radius) + oldCenter = mean(positions) + oldRadius, _ = findmax(x -> norm(x .- oldCenter), positions) + radF = radius / oldRadius + return Makie.Mat4f( + radF, + 0, + 0, + 0, + 0, + radF, + 0, + 0, + 0, + 0, + 1, + 0, + center[1] - oldCenter[1] * radF, + center[2] - oldCenter[2] * radF, + 0, + 1, + ) +end diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 0a09148a0..2a964e765 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -157,30 +157,6 @@ function plot_erp!( return f end -function eeg_head_matrix(positions, center, radius) - oldCenter = mean(positions) - oldRadius, _ = findmax(x -> norm(x .- oldCenter), positions) - radF = radius / oldRadius - return Makie.Mat4f( - radF, - 0, - 0, - 0, - 0, - radF, - 0, - 0, - 0, - 0, - 1, - 0, - center[1] - oldCenter[1] * radF, - center[2] - oldCenter[2] * radF, - 0, - 1, - ) -end - function add_significance(plot_data, significance, config) p = deepcopy(significance) diff --git a/test/test_butterfly.jl b/test/test_butterfly.jl index 8115eafcc..0d8d162ef 100644 --- a/test/test_butterfly.jl +++ b/test/test_butterfly.jl @@ -25,7 +25,7 @@ end plot_butterfly!(f[1, 1], mat; positions = pos) end -@testset "butterfly: witout topolegend" begin +@testset "butterfly: without topolegend" begin plot_butterfly( df; positions = pos, @@ -39,9 +39,8 @@ end plot_butterfly( df; positions = pos, - topomarkersize = 10, - topoheight = 0.4, - topowidth = 0.4, + topomarkersize = 70, + topo_axis = (; height = Relative(0.4), width = Relative(0.4)), ) end @@ -70,8 +69,7 @@ end f[1, 1], df; positions = pos, - topoheight = 0.4, - topowidth = 0.4, + topo_axis = (; height = Relative(0.4), width = Relative(0.4)), layout = (; hidedecorations = (:label => true, :ticks => true, :ticklabels => true) ), diff --git a/test/test_complexplots.jl b/test/test_complexplots.jl index 40907b2f6..fe46139bc 100644 --- a/test/test_complexplots.jl +++ b/test/test_complexplots.jl @@ -34,8 +34,7 @@ d_topo; positions = pos, topomarkersize = 10, - topoheight = 0.4, - topowidth = 0.4, + topo_axis = (; height = Relative(0.4), width = Relative(0.4)), ) hlines!(0, color = :gray, linewidth = 1) vlines!(0, color = :gray, linewidth = 1) From e11fa1c6f2646dd641b7707bc6954da848c87fd3 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 19:17:34 +0000 Subject: [PATCH 48/67] easy bug --- test/test_splines.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_splines.jl b/test/test_splines.jl index 5ec68bac7..0dca135a9 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -11,7 +11,7 @@ m2 = example_data("UnfoldLinearModelwith2Splines") catch err1 end @test err1 == AssertionError( - "No spline term is found in UnfoldModel. Did you forget to provide spline a formula?", + "No spline term is found in UnfoldModel. Does your UnfoldModel really have a `spl(...)` or other `AbstractSplineTerm`?", ) end From 87cf547c08d503e8c40b0e789b076ef571bb96eb Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 19:19:18 +0000 Subject: [PATCH 49/67] bug --- docs/literate/how_to/hide_deco.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/literate/how_to/hide_deco.jl b/docs/literate/how_to/hide_deco.jl index af9600a58..02eb0f1b2 100644 --- a/docs/literate/how_to/hide_deco.jl +++ b/docs/literate/how_to/hide_deco.jl @@ -41,7 +41,6 @@ plot_butterfly!( positions = pos, topomarkersize = 10, topo_axis = (; height = Relative(0.4), width = Relative(0.4)), - opoheight = 0.4, axis = (; title = "Without decorations"), layout = (; hidedecorations = (:label => true, :ticks => true, :ticklabels => true)), ) From 3d1b902650c2500bd3bceeb2b5fe793a7e09f6ec Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 20:51:55 +0000 Subject: [PATCH 50/67] minor changes in docs --- docs/literate/tutorials/erp.jl | 2 +- docs/literate/tutorials/topoplotseries.jl | 14 ++++++++++++-- src/plot_butterfly.jl | 3 ++- src/plot_topoplotseries.jl | 7 +------ test/test_toposeries1.jl | 4 ++++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/docs/literate/tutorials/erp.jl b/docs/literate/tutorials/erp.jl index cd7cddb15..2491fa576 100644 --- a/docs/literate/tutorials/erp.jl +++ b/docs/literate/tutorials/erp.jl @@ -108,7 +108,7 @@ text!(0.98, 0.2, text = "* Confidence\nintervals", align = (:right, :top)) f # There are two ways to implement it. -# First is using `:stderror = true' after `;`. +# First is using `:stderror = true` after `;`. results.se_low = results.estimate .- 0.5 results.se_high = results.estimate .+ 0.15 diff --git a/docs/literate/tutorials/topoplotseries.jl b/docs/literate/tutorials/topoplotseries.jl index 9c12cb578..410b30735 100644 --- a/docs/literate/tutorials/topoplotseries.jl +++ b/docs/literate/tutorials/topoplotseries.jl @@ -25,11 +25,21 @@ nothing #hide # `bin_width` - specify the interval between topoplots bin_width = 80 -plot_topoplotseries(df; bin_width, positions = positions) +plot_topoplotseries( + df; + bin_width, + positions = positions, + axis = (; xlabel = "Time windows [s]"), +) # `bin_num` - specify the number of topoplots -plot_topoplotseries(df; bin_num = 5, positions = positions) +plot_topoplotseries( + df; + bin_num = 5, + positions = positions, + axis = (; xlabel = "Time windows [s]"), +) # # Categorical and contionous x-values # By deafult x-value is `time`, but it could be any contionous (i.g. saccade amplitude) or categorical (any experimental variable) value. diff --git a/src/plot_butterfly.jl b/src/plot_butterfly.jl index e26e6625d..783a99623 100644 --- a/src/plot_butterfly.jl +++ b/src/plot_butterfly.jl @@ -36,7 +36,8 @@ Plot a Butterfly plot. - `topo_axis.height::Real = 0.25` \\ Change the height of inlay topoplot. - `mapping = (;)`\\ - For highlighting specific channels. + For highlighting specific channels.\\ + Example: `mapping = (; color = :highlight))`, where `:highlight` is variable with appopriate mapping. **Return Value:** `Figure` displaying Butterfly plot. diff --git a/src/plot_topoplotseries.jl b/src/plot_topoplotseries.jl index 0c75455e5..dcdee3652 100644 --- a/src/plot_topoplotseries.jl +++ b/src/plot_topoplotseries.jl @@ -80,6 +80,7 @@ function plot_topoplotseries!( config = PlotConfig(:topoplotseries) # overwrite all defaults by user specified values config_kwargs!(config; kwargs...) + # resolve columns with data config.mapping = resolve_mappings(to_value(data), config.mapping) data_copy = deepcopy(to_value(data)) # deepcopy prevents overwriting initial data @@ -141,12 +142,6 @@ function plot_topoplotseries!( colorbar = (; colorrange = colorrange), ) - config_kwargs!( - config, - visual = (; colorrange = colorrange), - colorbar = (; colorrange = colorrange), - ) - ax = Axis( f[1, 1]; (p for p in pairs(config.axis) if p[1] != :xlim_topo && p[1] != :ylim_topo)..., diff --git a/test/test_toposeries1.jl b/test/test_toposeries1.jl index cdf981ef9..ead15dc40 100644 --- a/test/test_toposeries1.jl +++ b/test/test_toposeries1.jl @@ -12,6 +12,10 @@ end plot_topoplotseries(df; bin_num = 5, positions = positions) end +@testset "toposeries: bin_num" begin + plot_topoplotseries(df; bin_num = 5, positions = positions, axis = (; xlabel = "test")) +end + @testset "toposeries: checking other y value" begin df.cont = df.time .* 3 plot_topoplotseries(df; bin_num = 5, positions = positions, mapping = (; col = :cont)) From 577b3b81bb645be2c0d39283a8d982018f3286de Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 21:25:43 +0000 Subject: [PATCH 51/67] indiv_docstrings - to show them in docs --- docs/literate/tutorials/splines.jl | 2 +- src/docstring_template.jl | 32 ++++++++++++++++++++++-------- src/plot_butterfly.jl | 16 +++------------ src/plot_splines.jl | 29 ++++++++++++--------------- src/plot_topoplotseries.jl | 2 +- 5 files changed, 42 insertions(+), 39 deletions(-) diff --git a/docs/literate/tutorials/splines.jl b/docs/literate/tutorials/splines.jl index 1e776053d..7ae9e57d8 100644 --- a/docs/literate/tutorials/splines.jl +++ b/docs/literate/tutorials/splines.jl @@ -1,6 +1,6 @@ # # [Spline plot](@id spline_vis) # **Spline plot** is a plot type for visualisation of terms in an UnfoldModel. -# Two subplots are generated for each spline term: 1) the basis function of the spline; 2) the density of the underlying covariate.\\ +# Two subplots are generated for each spline term: 1) the basis function of the spline; 2) the density of the underlying covariate. # Multiple spline terms are arranged across columns. # Dashed lines indicate spline knots. diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 1cb780dc7..64153c424 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -61,12 +61,28 @@ function _docstring(cfg_symb::Symbol) $(out) """ end -#= -""" - $(TYPEDSIGNATURES) -$(_docstring(:erp)) -""" -function plot_new() - return "b" -end =# +function indiv_docstrings(cfg_symb::Symbol) + # plot__splines + if cfg_symb == :spline_default + return (; + ylabel = "Spline value", + xlabelvisible = false, + xticklabelsvisible = false, + ylabelvisible = true, + ) + elseif cfg_symb == :density_default + return (; xautolimitmargin = (0, 0), ylabel = "Density value") + elseif cfg_symb == :superlabel_default + return (; fontsize = 20, padding = (0, 0, 40, 0)) + # plot_butterfly + elseif cfg_symb == :topo_default + return (; + width = Relative(0.35), + height = Relative(0.35), + halign = 0.05, + valign = 0.95, + aspect = 1, + ) + end +end diff --git a/src/plot_butterfly.jl b/src/plot_butterfly.jl index 783a99623..e386d76e8 100644 --- a/src/plot_butterfly.jl +++ b/src/plot_butterfly.jl @@ -30,11 +30,8 @@ Plot a Butterfly plot. Change the line colors. - `topo_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of the topoplot axis.\\ - To see all options just type `?Axis` in REPL. -- `topo_axis.width::Real = 0.25` \\ - Change the width of inlay topoplot. -- `topo_axis.height::Real = 0.25` \\ - Change the height of inlay topoplot. + To see all options just type `?Axis` in REPL.\\ + Defaults: $(indiv_docstrings(:topo_default)) - `mapping = (;)`\\ For highlighting specific channels.\\ Example: `mapping = (; color = :highlight))`, where `:highlight` is variable with appopriate mapping. @@ -131,14 +128,7 @@ function plot_butterfly!( f_grid = f[1, 1] if (topolegend) - topo_default = (; - width = Relative(0.35), - height = Relative(0.35), - halign = 0.05, - valign = 0.95, - aspect = 1, - ) - topo_axis = update_axis(topo_default; topo_axis...) + topo_axis = update_axis(indiv_docstrings(:topo_default); topo_axis...) ix = unique(i -> plot_data[:, config.mapping.group[1]][i], 1:size(plot_data, 1)) topoplot_legend( diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 77f24249e..2168a2df1 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -1,4 +1,5 @@ using BSplineKit, Unfold + """ plot_splines(m::UnfoldModel; kwargs...) plot_splines!(f::Union{GridPosition, GridLayout, Figure}, m::UnfoldModel; kwargs...) @@ -7,7 +8,7 @@ Visualization of spline terms in an UnfoldModel. Two subplots are generated for 1) the basis function of the spline; 2) the density of the underlying covariate.\\ Multiple spline terms are arranged across columns. -Dashed lines indicate spline knots. +Dashed lines indicate spline knots. ## Arguments: @@ -17,13 +18,17 @@ Dashed lines indicate spline knots. UnfoldModel with splines. - `spline_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of spline subplots.\\ - To see all options just type `?Axis` in REPL. + To see all options just type `?Axis` in REPL.\\ + Defaults: $(indiv_docstrings(:spline_default)) - `density_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of density subplots.\\ - To see all options just type `?Axis` in REPL. + To see all options just type `?Axis` in REPL.\\ + Defaults: $(indiv_docstrings(:density_default)) - `superlabel_config::NamedTuple = (;)`\\ Here you can flexibly change configurations of the Label on the top of the plot.\\ - To see all options just type `?Label` in REPL. + To see all options just type `?Label` in REPL.\\ + Defaults: $(indiv_docstrings(:superlabel_default)) + $(_docstring(:splines)) **Return Value:** `Figure` with splines and their density for basis functions. @@ -93,17 +98,9 @@ function plot_splines( end function supportive_axes_management(spline_axis, density_axis, superlabel_config) - spline_default = (; - ylabel = "Spline value", - xlabelvisible = false, - xticklabelsvisible = false, - ylabelvisible = true, - ) - density_default = (; xautolimitmargin = (0, 0), ylabel = "Density value") - superlabel_default = (; fontsize = 20, padding = (0, 0, 40, 0)) - - spline_axis = update_axis(spline_default; spline_axis...) - density_axis = update_axis(density_default; density_axis...) - superlabel_config = update_axis(superlabel_default; superlabel_config...) + spline_axis = update_axis(indiv_docstrings(:spline_default); spline_axis...) + density_axis = update_axis(indiv_docstrings(:density_default); density_axis...) + superlabel_config = + update_axis(indiv_docstrings(:superlabel_default); superlabel_config...) return spline_axis, density_axis, superlabel_config end diff --git a/src/plot_topoplotseries.jl b/src/plot_topoplotseries.jl index dcdee3652..494c11489 100644 --- a/src/plot_topoplotseries.jl +++ b/src/plot_topoplotseries.jl @@ -42,7 +42,7 @@ Multiple miniature topoplots in regular distances. `mapping.col` - specify x-value, can be any continuous or categorical variable.\\ `mapping.row` - specify y-value, can be any continuous or categorical variable (not implemented yet).\\ `mapping.layout` - arranges topoplots by rows when equals `:time`.\\ -- `visual..colorrange::2-element Vector{Int64}`\\ +- `visual.colorrange::2-element Vector{Int64}`\\ Resposnible for colorrange in topoplots and in colorbar. From a855d9c3e3b1c42ecb459e31d8790b68d0cef3e0 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 21:42:14 +0000 Subject: [PATCH 52/67] also for plot_erpimage --- src/docstring_template.jl | 10 ++++++++++ src/plot_erpimage.jl | 16 +++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 64153c424..34c6c805b 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -84,5 +84,15 @@ function indiv_docstrings(cfg_symb::Symbol) valign = 0.95, aspect = 1, ) + # plot_erpimage + elseif cfg_symb == :meanplot_default + return (; + height = 100, + xlabel = "Time [s]", + xlabelpadding = 0, + xautolimitmargin = (0, 0), + ) + elseif cfg_symb == :sortplot_default + return (; ylabelvisible = true, yticklabelsvisible = false) end end diff --git a/src/plot_erpimage.jl b/src/plot_erpimage.jl index 7847c796d..2cbd490e3 100644 --- a/src/plot_erpimage.jl +++ b/src/plot_erpimage.jl @@ -33,10 +33,12 @@ Plot an ERP image. If `sortvalues = true` the default text will change to "Sorted trials", but it could be changed to any values specified manually. - `meanplot_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of meanplot.\\ - To see all options just type `?Axis` in REPL. + To see all options just type `?Axis` in REPL.\\ + Defaults: $(indiv_docstrings(:meanplot_default)) - `sortplot_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of meanplot.\\ - To see all options just type `?Axis` in REPL. + To see all options just type `?Axis` in REPL.\\ + Defaults: $(indiv_docstrings(:sortplot_default)) $(_docstring(:erpimage)) @@ -134,13 +136,11 @@ function ei_meanplot(ax, data, config, f, ga, times, meanplot_axis) ax.xticklabelsvisible = false trace = @lift(mean($data, dims = 2)[:, 1]) + meanplot_axis = update_axis(indiv_docstrings(:meanplot_default); meanplot_axis...) + axbottom = Axis( ga[5, 1:4]; - height = 100, ylabel = config.colorbar.label === nothing ? "" : config.colorbar.label, - xlabel = "Time [s]", - xlabelpadding = 0, - xautolimitmargin = (0, 0), limits = @lift(( minimum($times), maximum($times), @@ -163,11 +163,10 @@ function ei_sortvalue(sortvalues, f, ax, hm, config, sortval_xlabel, sortplot_ax error("`show_sortval` can not take `sortvalues` with all NaN-values") end gb = f[1, 3] = GridLayout() + sortplot_axis = update_axis(indiv_docstrings(:sortplot_default); sortplot_axis...) axleft = Axis( gb[1:4, 1:5]; xlabel = sortval_xlabel, - ylabelvisible = true, - yticklabelsvisible = false, #xautolimitmargin = (-1, 1), #yautolimitmargin = (1, 100), xticks = @lift([ @@ -188,7 +187,6 @@ function ei_sortvalue(sortvalues, f, ax, hm, config, sortval_xlabel, sortplot_ax hidedecorations!(axempty) hidespines!(axempty) hidespines!(axleft, :r, :t) - #scatter!(axleft, xs, ys) lines!(axleft, xs, ys) if config.layout.use_colorbar != false Colorbar( From 120075e234e65e1784ef8e7af9a13e9167248f5b Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Fri, 20 Sep 2024 21:47:48 +0000 Subject: [PATCH 53/67] same for buttergly --- test/test_splines.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_splines.jl b/test/test_splines.jl index 0dca135a9..e6e7c6a85 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -23,10 +23,6 @@ end plot_splines(m2) end -@testset "Spline plot: superlabel_axis check" begin - plot_splines(m2; superlabel_config = (; fontsize = 60)) -end - @testset "Spline plot: spline_axis check" begin plot_splines(m2; spline_axis = (; ylabel = "test")) end @@ -34,3 +30,7 @@ end @testset "Spline plot: density_axis check" begin plot_splines(m2, density_axis = (; ylabel = "test")) end + +@testset "Spline plot: superlabel_axis check" begin + plot_splines(m2; superlabel_config = (; fontsize = 60)) +end From 022e7c448b70a6d438dfe7c8e87d23f4211c0f3d Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 09:50:31 +0000 Subject: [PATCH 54/67] issue 236 --- docs/example_data.jl | 96 +++++++++++++++++++++++-------------------- src/plot_butterfly.jl | 2 +- src/plot_splines.jl | 2 +- 3 files changed, 54 insertions(+), 46 deletions(-) diff --git a/docs/example_data.jl b/docs/example_data.jl index ef67f50bd..e76b123c7 100644 --- a/docs/example_data.jl +++ b/docs/example_data.jl @@ -6,57 +6,34 @@ using Random """ example_data(String) -Creates example data. Currently, 7 datasets are available. -- `TopoPlots.jl` (default) - tidy DataFrame from `TopoPlots.jl` with 2 conditions, 64 channels and 800 ms time range. -- `UnfoldLinearModel` -- `UnfoldLinearModelMultiChannel` -- `UnfoldLinearModelContinuousTime` -- `7channels` -- `UnfoldTimeExpanded` -- `sort_data` - includes DataFrame EEG recordings `dat` and `evts` with event variables occured during experiment. `evts` could be used for sorting EEG data in ERP image. +Creates example data or model. Currently, 3 datasets and 6 models are available. + +Datasets: +- `TopoPlots.jl` (default) - 2 DataFrames from `TopoPlots.jl`:\\ + - DataFrame with estimate, time, 64 channels, topopositions, sterror and pvalue and 800 ms time range.\\ + - Posiions for 64 electrodes. +- `UnfoldLinearModelMultiChannel` - DataFrame with 5 channels, 3 coefnames, sterror, time and estimate. +- `sort_data` - 2 DataFrames: + - `dat` for EEG recordings and `evts` with event variables occured during experiment.\\ + - `evts` could be used for sorting EEG data in ERP image. + +Models: +- `UnfoldLinearModel` - Model with formula `1 + condition + continuous`. +- `UnfoldLinearModelContinuousTime` - Model with formula `timeexpand(1 + condition + continuous)` for times [0.0, 0.01 ... 0.5]. +- `UnfoldLinearModelwith1Spline` - Model with formula `1 + condition + spl(continuous, 4)`. +- `UnfoldLinearModelwith2Splines` - Model with formula ` 1 + condition + spl(continuous, 4) + spl(continuous2, 6)`. +- `7channels` - Model with formula `timeexpand(1 + condA)` for times [-0.1, -0.09 ... 0.5]. +- `UnfoldTimeExpanded` - Model with formula `timeexpand(1 + condition + continuous)` for times [-0.4, -0.39 ... 0.8]. + **Return Value:** `DataFrame`. """ function example_data(example = "TopoPlots.jl") - if example == "UnfoldLinearModel" - # load and generate a simulated Unfold Design data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) data = reshape(data, (1, size(data)...)) f = @formula 0 ~ 1 + condition + continuous - # generate ModelStruct - se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) - return fit( - UnfoldModel, - [Any => (f, range(0, length = size(data, 2), step = 1 / 100))], - evts, - data; - solver = se_solver, - ) - elseif example == "UnfoldLinearModelwith1Spline" - # load and generate a simulated Unfold Design - data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) - data = reshape(data, (1, size(data)...)) - evts.continuous2 .= - log10.(6 .+ rand(MersenneTwister(1), length(evts.continuous))) .^ 2 - f = @formula 0 ~ 1 + condition + spl(continuous, 4) - # generate ModelStruct - se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) - return fit( - UnfoldModel, - [Any => (f, range(0, length = size(data, 2), step = 1 / 100))], - evts, - data; - solver = se_solver, - ) - elseif example == "UnfoldLinearModelwith2Splines" - # load and generate a simulated Unfold Design - data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) - data = reshape(data, (1, size(data)...)) - evts.continuous2 .= - log10.(6 .+ rand(MersenneTwister(1), length(evts.continuous))) .^ 2 - f = @formula 0 ~ 1 + condition + spl(continuous, 4) + spl(continuous2, 6) - # generate ModelStruct + # generate ModelStruct se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) return fit( UnfoldModel, @@ -105,6 +82,38 @@ function example_data(example = "TopoPlots.jl") basis = firbasis([0, 0.5], 100) # generate ModelStruct return fit(UnfoldModel, [Any => (f, basis)], evts, data) + elseif example == "UnfoldLinearModelwith1Spline" + # load and generate a simulated Unfold Design + data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) + data = reshape(data, (1, size(data)...)) + evts.continuous2 .= + log10.(6 .+ rand(MersenneTwister(1), length(evts.continuous))) .^ 2 + f = @formula 0 ~ 1 + condition + spl(continuous, 4) + # generate ModelStruct + se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) + return fit( + UnfoldModel, + [Any => (f, range(0, length = size(data, 2), step = 1 / 100))], + evts, + data; + solver = se_solver, + ) + elseif example == "UnfoldLinearModelwith2Splines" + # load and generate a simulated Unfold Design + data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) + data = reshape(data, (1, size(data)...)) + evts.continuous2 .= + log10.(6 .+ rand(MersenneTwister(1), length(evts.continuous))) .^ 2 + f = @formula 0 ~ 1 + condition + spl(continuous, 4) + spl(continuous2, 6) + # generate ModelStruct + se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) + return fit( + UnfoldModel, + [Any => (f, range(0, length = size(data, 2), step = 1 / 100))], + evts, + data; + solver = se_solver, + ) elseif example == "7channels" design = SingleSubjectDesign(conditions = Dict(:condA => ["levelA", "levelB"])) |> @@ -122,7 +131,6 @@ function example_data(example = "TopoPlots.jl") f = @formula 0 ~ 1 + condA bf_dict = [Any => (f, basisfunction)] return fit(UnfoldModel, bf_dict, evnts, df) - elseif example == "UnfoldTimeExpanded" df, evts = UnfoldSim.predef_eeg() f = @formula 0 ~ 1 + condition + continuous diff --git a/src/plot_butterfly.jl b/src/plot_butterfly.jl index e386d76e8..7d668204c 100644 --- a/src/plot_butterfly.jl +++ b/src/plot_butterfly.jl @@ -53,7 +53,7 @@ function plot_butterfly!( topomarkersize = 10, topopositions_to_color = x -> pos_to_color_RomaO(x), topo_axis = (;), - mapping = (;), # WTf?? + mapping = (;), kwargs..., ) diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 2168a2df1..5b6597b3c 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -8,7 +8,7 @@ Visualization of spline terms in an UnfoldModel. Two subplots are generated for 1) the basis function of the spline; 2) the density of the underlying covariate.\\ Multiple spline terms are arranged across columns. -Dashed lines indicate spline knots. +Dashed lines indicate spline knots. ## Arguments: From 0c48f1331c3553f8bebadd30f99093b0009eec0e Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 10:24:40 +0000 Subject: [PATCH 55/67] issue 222 --- src/plot_circular_topoplots.jl | 6 ++---- src/plot_splines.jl | 2 +- src/plotconfig.jl | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/plot_circular_topoplots.jl b/src/plot_circular_topoplots.jl index 635a8bc14..05f2744f7 100644 --- a/src/plot_circular_topoplots.jl +++ b/src/plot_circular_topoplots.jl @@ -83,10 +83,9 @@ function plot_circular_topoplots!( # setting the colorbar to the bottom right of the box. # Relative values got determined by checking what subjectively looks best Colorbar( - f[1, 2], - colormap = config.colorbar.colormap, + f[1, 2]; colorrange = (min, max), - label = config.colorbar.label, + config.colorbar..., height = @lift Fixed($(pixelarea(ax.scene)).widths[2]) ) plot_topo_plots!( @@ -102,7 +101,6 @@ function plot_circular_topoplots!( ) apply_layout_settings!(config; ax = ax) - # set the scene's background color according to config #set_theme!(Theme(backgroundcolor = config.axisData.backgroundcolor)) return f diff --git a/src/plot_splines.jl b/src/plot_splines.jl index 5b6597b3c..d75a2d909 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -7,7 +7,7 @@ using BSplineKit, Unfold Visualization of spline terms in an UnfoldModel. Two subplots are generated for each spline term:\\ 1) the basis function of the spline; 2) the density of the underlying covariate.\\ -Multiple spline terms are arranged across columns. +Multiple spline terms are arranged across columns.\\ Dashed lines indicate spline knots. ## Arguments: diff --git a/src/plotconfig.jl b/src/plotconfig.jl index b8dc8e827..36d934bbc 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -48,6 +48,7 @@ function PlotConfig()# defaults vertical = true, tellwidth = true, tellheight = false, + labelrotation = -π / 2, ), ) end @@ -61,7 +62,11 @@ function PlotConfig(T::Val{:circtopos}) config_kwargs!( cfg; layout = (; show_legend = false), - colorbar = (; label = "Voltage [µV]", colormap = Reverse(:RdBu)), + colorbar = (; + labelrotation = -π / 2, + label = "Voltage [µV]", + colormap = Reverse(:RdBu), + ), mapping = (;), axis = (; label = "" @@ -95,7 +100,7 @@ function PlotConfig(T::Val{:topoplot}) positions = (:pos, :positions, :position, nothing), # Point / Array / Tuple labels = (:labels, :label, :sensor, nothing), # String ), - colorbar = (; flipaxis = true, labelrotation = -π / 2, label = "Voltage [µV]"), + colorbar = (; flipaxis = true, label = "Voltage [µV]"), axis = (; xlabel = "", aspect = DataAspect()), ) return cfg @@ -120,12 +125,7 @@ function PlotConfig(T::Val{:topoplotseries}) yrectzoom = false, ), layout = (; use_colorbar = true), - colorbar = (; - flipaxis = true, - labelrotation = -π / 2, - label = "Voltage [µV]", - colorrange = nothing, - ), + colorbar = (; flipaxis = true, label = "Voltage [µV]", colorrange = nothing), visual = (; label_text = false, # true doesnt work again colormap = Reverse(:RdBu), @@ -147,7 +147,7 @@ function PlotConfig(T::Val{:designmat}) ylabel = "Trials", xticklabelrotation = round(pi / 8, digits = 2), ), - colorbar = (; flipaxis = true, labelrotation = -π / 2, label = ""), + colorbar = (; flipaxis = true, label = ""), ) return cfg end @@ -213,7 +213,7 @@ function PlotConfig(T::Val{:erp}) yticklabelsize = 14, xtickformat = "{:.1f}", ), - colorbar = (; label = "", flipaxis = true, labelrotation = -π / 2), + colorbar = (; label = "", flipaxis = true), ) return cfg @@ -241,7 +241,7 @@ function PlotConfig(T::Val{:channelimage}) config_kwargs!( cfg; #layout = (; use_colorbar = true), - colorbar = (; label = "Voltage [µV]", labelrotation = -π / 2), + colorbar = (; label = "Voltage [µV]"), axis = (xlabel = "Time [s]", ylabel = "Channels", yticklabelsize = 14), visual = (; colormap = Reverse("RdBu")), #cork ) @@ -252,7 +252,7 @@ function PlotConfig(T::Val{:erpimage}) config_kwargs!( cfg; layout = (; use_colorbar = true, show_legend = false), - colorbar = (; label = "Voltage [µV]", labelrotation = -π / 2), + colorbar = (; label = "Voltage [µV]"), axis = (xlabel = "Time [s]", ylabel = "Trials"), visual = (; colormap = Reverse("RdBu")), ) From 09ca287f8c80db040c179c96f58d49194d17deed Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 12:20:26 +0000 Subject: [PATCH 56/67] customizable plot_erpgrid, issue 94 --- src/docstring_template.jl | 9 +++++++ src/plot_erpgrid.jl | 57 ++++++++++++++++++++++++++++----------- src/plotconfig.jl | 1 + test/test_erpgrid.jl | 29 ++++++++++++++++++++ 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 34c6c805b..8d5f3fce5 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -94,5 +94,14 @@ function indiv_docstrings(cfg_symb::Symbol) ) elseif cfg_symb == :sortplot_default return (; ylabelvisible = true, yticklabelsvisible = false) + # plot_erpgrid + elseif cfg_symb == :hlines_grid_default + return (; color = :gray, linewidth = 0.5) + elseif cfg_symb == :vlines_grid_default + return (; color = :gray, linewidth = 0.5, ymin = 0.2, ymax = 0.8) + elseif cfg_symb == :lines_grid_default + return (; color = :deepskyblue3) + elseif cfg_symb == :labels_grid_default + return (; color = :gray, fontsize = 12, align = (:left, :top), space = :relative) end end diff --git a/src/plot_erpgrid.jl b/src/plot_erpgrid.jl index ef06456ac..2639db53e 100644 --- a/src/plot_erpgrid.jl +++ b/src/plot_erpgrid.jl @@ -13,6 +13,23 @@ Plot an ERP image. Electrode positions. - `ch_names::Vector{String}`\\ Vector with channel names. +- `hlines_grid_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the hline axis.\\ + To see all options just type `?hlines` in REPL.\\ + Defaults: $(indiv_docstrings(:hlines_grid_default)) +- `vlines_grid_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the vline axis.\\ + To see all options just type `?vlines` in REPL.\\ + Defaults: $(indiv_docstrings(:vlines_grid_default)) +- `lines_grid_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the lines axis.\\ + To see all options just type `?lines` in REPL.\\ + Defaults: $(indiv_docstrings(:lines_grid_default)) +- `labels_grid_axis::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the labels axis.\\ + To see all options just type `?text` in REPL.\\ + Defaults: $(indiv_docstrings(:lables_grid_default)) + ## Keyword arguments (kwargs) - `drawlabels::Bool = false`\\ @@ -48,6 +65,10 @@ function plot_erpgrid!( ch_names::Vector{String}; drawlabels = false, times = -1:size(data, 2)-2, #arbitrary + labels_grid_axis = (;), + hlines_grid_axis = (;), + vlines_grid_axis = (;), + lines_grid_axis = (;), kwargs..., ) config = PlotConfig(:erpgrid) @@ -72,6 +93,8 @@ function plot_erpgrid!( axlist = [] rel_zeropoint = argmin(abs.(times)) ./ length(times) + labels_grid_axis = + update_axis(indiv_docstrings(:labels_grid_default); labels_grid_axis...) for (ix, p) in enumerate(eachcol(positions)) x = p[1] y = p[2] @@ -83,29 +106,25 @@ function plot_erpgrid!( valign = y, ) if drawlabels - text!( - ax, - rel_zeropoint + 0.1, - 1, - color = :gray, - fontsize = 12, - text = ch_names[ix], - align = (:left, :top), - space = :relative, - ) + text!(ax, rel_zeropoint + 0.1, 1; text = ch_names[ix], labels_grid_axis...) end # todo: add label if not nothing push!(axlist, ax) end - # todo: make optional + be able to specify the linewidth + color - hlines!.(axlist, Ref([0.0]), color = :gray, linewidth = 0.5) - vlines!.(axlist, Ref([0.0]), color = :gray, linewidth = 0.5) + hlines_grid_axis = + update_axis(indiv_docstrings(:hlines_grid_default); hlines_grid_axis...) + vlines_grid_axis = + update_axis(indiv_docstrings(:vlines_grid_default); vlines_grid_axis...) + lines_grid_axis = update_axis(indiv_docstrings(:lines_grid_default); lines_grid_axis...) + + hlines!.(axlist, Ref([0.0]); hlines_grid_axis...) + vlines!.(axlist, Ref([0.0]); vlines_grid_axis...) times = isnothing(times) ? (1:size(data, 2)) : times # todo: add customizable kwargs - h = lines!.(axlist, Ref(times), eachrow(data)) + h = lines!.(axlist, Ref(times), eachrow(data); lines_grid_axis...) linkaxes!(axlist...) hidedecorations!.(axlist) @@ -119,14 +138,20 @@ function plot_erpgrid!( xstart = [Point2f(0), Point2f(0)] xdir = [Vec2f(0, 0.1), Vec2f(0.1, 0)] arrows!(xstart, xdir, arrowsize = 10) - text!(0.02, 0, text = config.axis.xlabel, align = (:left, :top), fontsize = 12) + text!( + 0.02, + 0, + text = config.axis.xlabel, + fontsize = config.axis.fontsize, + align = (:left, :top), + ) text!( -0.008, 0.01, text = config.axis.ylabel, + fontsize = config.axis.fontsize, align = (:left, :baseline), rotation = π / 2, - fontsize = 12, ) f end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 36d934bbc..7d759e57d 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -231,6 +231,7 @@ function PlotConfig(T::Val{:erpgrid}) ylabel = "Voltage [µV]", xlim = [-0.04, 1], ylim = [-0.04, 1], + fontsize = 12, ), ) return cfg diff --git a/test/test_erpgrid.jl b/test/test_erpgrid.jl index a7caf4fbd..d574a361e 100644 --- a/test/test_erpgrid.jl +++ b/test/test_erpgrid.jl @@ -25,6 +25,35 @@ end plot_erpgrid(data[1:6, :], pos[1:6], raw_ch_names[1:6]; drawlabels = true) end +@testset "erpgrid: customizable labels" begin + plot_erpgrid( + data[1:6, :], + pos[1:6], + raw_ch_names[1:6]; + drawlabels = true, + labels_grid_axis = (; color = :red), + ) +end + +@testset "erpgrid: customizable vlines and hlines" begin + plot_erpgrid( + data[1:6, :], + pos[1:6], + raw_ch_names[1:6]; + hlines_grid_axis = (; color = :red), + vlines_grid_axis = (; color = :green), + ) +end + +@testset "erpgrid: customizable lines" begin + plot_erpgrid( + data[1:6, :], + pos[1:6], + raw_ch_names[1:6]; + lines_grid_axis = (; color = :red), + ) +end + @testset "erpgrid: GridPosition" begin f = Figure() plot_erpgrid!(f[1, 1], data, pos) From be27c4f669e8b85b0f89ccc8d8fc4d58eb0c73b8 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 12:30:18 +0000 Subject: [PATCH 57/67] issue 205 --- docs/literate/tutorials/erp.jl | 3 +++ src/docstring_template.jl | 2 +- src/plot_erpgrid.jl | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/literate/tutorials/erp.jl b/docs/literate/tutorials/erp.jl index 2491fa576..676633b6b 100644 --- a/docs/literate/tutorials/erp.jl +++ b/docs/literate/tutorials/erp.jl @@ -36,6 +36,9 @@ res_effects = effects(Dict(:continuous => -5:0.5:5), m); # ## Figure plotting plot_erp(results) +# To change legend title use `mapping.color`: +plot_erp(results, mapping = (; color = :coefname => "Conditions")) + # # Additional features # ## Effect plot diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 8d5f3fce5..0f3ae20be 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -63,7 +63,7 @@ function _docstring(cfg_symb::Symbol) end function indiv_docstrings(cfg_symb::Symbol) - # plot__splines + # plot_splines if cfg_symb == :spline_default return (; ylabel = "Spline value", diff --git a/src/plot_erpgrid.jl b/src/plot_erpgrid.jl index 2639db53e..d49195e3a 100644 --- a/src/plot_erpgrid.jl +++ b/src/plot_erpgrid.jl @@ -28,8 +28,7 @@ Plot an ERP image. - `labels_grid_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of the labels axis.\\ To see all options just type `?text` in REPL.\\ - Defaults: $(indiv_docstrings(:lables_grid_default)) - + Defaults: $(indiv_docstrings(:labels_grid_default)) ## Keyword arguments (kwargs) - `drawlabels::Bool = false`\\ From 211a444ec3f2d229134f3f3e85559fa7d637f416 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 12:43:58 +0000 Subject: [PATCH 58/67] add links to docstrings --- src/docstring_template.jl | 4 +++- src/plotconfig.jl | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 0f3ae20be..81811f4bd 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -37,8 +37,10 @@ function _docstring(cfg_symb::Symbol) :figure => "use `kwargs...` of [`Makie.Figure`](https://docs.makie.org/stable/explanations/figure/)", :axis => "use `kwargs...` of [`Makie.Axis`](https://docs.makie.org/stable/reference/blocks/axis/)", :legend => "use `kwargs...` of [`Makie.Legend`](https://docs.makie.org/stable/reference/blocks/legend/)", - :colorbar => "use `kwargs...` of $cbarstring", + :layout => "check this [page](https://unfoldtoolbox.github.io/UnfoldMakie.jl/dev/generated/how_to/hide_deco/)", + :mapping => "use any mapping from [`AlgebraOfGraphics`](https://aog.makie.org/stable/layers/mapping/)", :visual => "use `kwargs...` of [$(visuallink[cfg_symb])]($(visuallink2[cfg_symb]))", + :colorbar => "use `kwargs...` of $cbarstring", ) for k = 1:length(fn) namedtpl = string(Base.getfield(cfg, fn[k])) diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 7d759e57d..3c245465a 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -28,7 +28,7 @@ function PlotConfig()# defaults (;), # axis (; # layout show_legend = true, - use_colorbar = true, # ideally should be deleted + use_colorbar = true, ), (#maping x = (:time,), From a4660ebb99db3ba35853e23068f6f107819fbd5e Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 13:20:52 +0000 Subject: [PATCH 59/67] issue 106 --- docs/literate/how_to/mult_vis_in_fig.jl | 2 -- docs/literate/tutorials/erp.jl | 2 +- src/docstring_template.jl | 2 +- src/plot_topoplot.jl | 2 +- src/plotconfig.jl | 4 +--- test/test_complexplots.jl | 1 - test/test_pcp.jl | 4 +--- test/test_topoplot.jl | 2 +- 8 files changed, 6 insertions(+), 13 deletions(-) diff --git a/docs/literate/how_to/mult_vis_in_fig.jl b/docs/literate/how_to/mult_vis_in_fig.jl index e409b21b5..bfc65d2bd 100644 --- a/docs/literate/how_to/mult_vis_in_fig.jl +++ b/docs/literate/how_to/mult_vis_in_fig.jl @@ -89,14 +89,12 @@ plot_erp!( res_effects; mapping = (; y = :yhat, color = :continuous, group = :continuous => nonnumeric), legend = (; nbanks = 2), - layout = (; show_legend = true, legend_position = :right), ) plot_parallelcoordinates( f[3, 2:3], uf_5chan; mapping = (; color = :coefname), - layout = (; legend_position = :right), ) plot_erpimage!(f[1, 4:5], times, d_singletrial) diff --git a/docs/literate/tutorials/erp.jl b/docs/literate/tutorials/erp.jl index 676633b6b..684564687 100644 --- a/docs/literate/tutorials/erp.jl +++ b/docs/literate/tutorials/erp.jl @@ -56,7 +56,7 @@ plot_erp(results, mapping = (; color = :coefname => "Conditions")) plot_erp( res_effects; mapping = (; y = :yhat, color = :continuous, group = :continuous), - layout = (; show_legend = false), + layout = (; use_colorbar = false), ) # ## Significance lines diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 81811f4bd..73a323996 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -55,7 +55,7 @@ function _docstring(cfg_symb::Symbol) return """## Shared plot configuration options The shared plot options can be used as follows: `type = (; key = value, ...))`.\\ - For example, `plot_x(...; layout = (; show_legend = true, legend_position = :right))`.\\ + For example, `plot_x(...; colorbar = (; vertical = true, label = "Test"))`.\\ Multiple defaults will be cycled until match. Placing `;` is important! diff --git a/src/plot_topoplot.jl b/src/plot_topoplot.jl index 5134c9827..1c51fa46a 100644 --- a/src/plot_topoplot.jl +++ b/src/plot_topoplot.jl @@ -50,7 +50,7 @@ function plot_topoplot!( @warn """The min and max of the value represented by the color are the same, it seems that the data values are identical. We disable the color bar in this figure. Note: The identical min and max may cause an interpolation error when plotting the topoplot.""" - config_kwargs!(config, layout = (; use_colorbar = false, show_legend = false)) + config_kwargs!(config, layout = (; use_colorbar = false)) else config_kwargs!(config, colorbar = (; limits = clims)) end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 3c245465a..71587f65f 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -27,7 +27,6 @@ function PlotConfig()# defaults (;), #figure (;), # axis (; # layout - show_legend = true, use_colorbar = true, ), (#maping @@ -82,7 +81,6 @@ function PlotConfig(T::Val{:topoplot}) config_kwargs!( cfg; layout = ( - show_legend = true, use_colorbar = true, hidespines = (), hidedecorations = (Dict(:label => false)), @@ -252,7 +250,7 @@ function PlotConfig(T::Val{:erpimage}) cfg = PlotConfig() config_kwargs!( cfg; - layout = (; use_colorbar = true, show_legend = false), + layout = (; use_colorbar = true), colorbar = (; label = "Voltage [µV]"), axis = (xlabel = "Time [s]", ylabel = "Trials"), visual = (; colormap = Reverse("RdBu")), diff --git a/test/test_complexplots.jl b/test/test_complexplots.jl index fe46139bc..4837419bf 100644 --- a/test/test_complexplots.jl +++ b/test/test_complexplots.jl @@ -191,7 +191,6 @@ end f[2, 4:5], res_effects; mapping = (; y = :yhat, color = :continuous, group = :continuous => nonnumeric), - layout = (; show_legend = true), ) plot_parallelcoordinates(f[3, 2:3], uf_5chan; mapping = (; color = :coefname)) diff --git a/test/test_pcp.jl b/test/test_pcp.jl index 28016b181..bdf13257e 100644 --- a/test/test_pcp.jl +++ b/test/test_pcp.jl @@ -80,7 +80,7 @@ end plot_parallelcoordinates( uf_5chan; mapping = (; color = :coefname), - layout = (; legend_position = :right), + legend = (; valign = :center), ) end @@ -179,7 +179,6 @@ end f[1, 1], uf_5chan; mapping = (; color = :coefname), - layout = (; legend_position = :right), visual = (; alpha = 0.1), axis = (; title = "alpha = 0.1"), ) @@ -187,7 +186,6 @@ end f[2, 1], uf_5chan, mapping = (; color = :coefname), - layout = (; legend_position = :right), visual = (; alpha = 0.9), axis = (; title = "alpha = 0.9"), ) diff --git a/test/test_topoplot.jl b/test/test_topoplot.jl index 76508b89c..3fd2f7c14 100644 --- a/test/test_topoplot.jl +++ b/test/test_topoplot.jl @@ -26,7 +26,7 @@ end end @testset "topoplot: no legend" begin - plot_topoplot(dat[:, 50, 1]; positions = positions, layout = (; show_legend = false)) + plot_topoplot(dat[:, 50, 1]; positions = positions, layout = (; use_colorbar = false)) end @testset "topoplot: xlabel" begin From 8cb4a8a75fad378ee851f0c5225c8dfa283ce535 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 13:41:17 +0000 Subject: [PATCH 60/67] okay, reverse --- src/plotconfig.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 71587f65f..84dee391a 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -27,6 +27,7 @@ function PlotConfig()# defaults (;), #figure (;), # axis (; # layout + show_legend = true, use_colorbar = true, ), (#maping From 7681bddda46cc152cec4fe0f7a36cdff6764e6e7 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 14:13:42 +0000 Subject: [PATCH 61/67] issue 147 - indicator for topoplot --- docs/literate/tutorials/topoplot.jl | 3 +++ src/plot_erp.jl | 1 - src/plot_topoplot.jl | 26 +++++++++++++++++- test/test_topoplot.jl | 42 +++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/docs/literate/tutorials/topoplot.jl b/docs/literate/tutorials/topoplot.jl index 98c40b4a6..ba3eb9f45 100644 --- a/docs/literate/tutorials/topoplot.jl +++ b/docs/literate/tutorials/topoplot.jl @@ -91,6 +91,9 @@ plot_topoplot!( ) f +# # Highlighting channels +plot_topoplot(dat[:, 50, 1]; positions, high_chan = [1, 2]) + # # Configurations of Topoplot # ```@docs diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 2a964e765..c1ba6e8be 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -143,7 +143,6 @@ function plot_erp!( f_grid = f[1, 1] = GridLayout() drawing = draw!(f_grid, plot_equation; axis = config.axis) - if config.layout.show_legend == true config_kwargs!(config; mapping, layout = (; show_legend = false)) if config.layout.use_legend == true diff --git a/src/plot_topoplot.jl b/src/plot_topoplot.jl index 1c51fa46a..4df4551b6 100644 --- a/src/plot_topoplot.jl +++ b/src/plot_topoplot.jl @@ -1,5 +1,6 @@ """ plot_topoplot!(f::Union{GridPosition, GridLayout, Figure}, data::Union{<:AbstractDataFrame,<:AbstractVector}; positions::Vector, labels = nothing, kwargs...) +using Interpolations: positions plot_topoplot(data::Union{<:AbstractDataFrame,<:AbstractVector}; position::Vector, labels = nothing, kwargs...) Plot a topoplot. @@ -12,6 +13,8 @@ Plot a topoplot. Positions used if `data` is not a `DataFrame`. Positions are generated from `labels` if `positions = nothing`. - `labels::Vector{String} = nothing`\\ Labels used if `data` is not a DataFrame. +- `high_chan = nothing` - channnel(s) to highlight by color. +- `high_color = :darkgreen` - color for highlighting. $(_docstring(:topoplot)) @@ -25,6 +28,8 @@ function plot_topoplot!( data::Union{<:AbstractDataFrame,<:AbstractVector}; labels = nothing, positions = nothing, + high_chan = nothing, + high_color = :darkgreen, kwargs..., ) config = PlotConfig(:topoplot) @@ -41,7 +46,26 @@ function plot_topoplot!( positions = TopoPlots.labels2positions(labels) end positions = get_topo_positions(; positions = positions, labels = labels) - eeg_topoplot!(axis, data, labels; positions, config.visual...) + if isa(high_chan, Int) || isa(high_chan, Vector{Int64}) + x = zeros(length(positions)) + isa(high_chan, Int) ? x[high_chan] = 1 : x[high_chan] .= 1 + clist = [:gray, high_color][Int.(x .+ 1)] #color for highlighting + eeg_topoplot!( + axis, + data, + labels; + positions, + config.visual..., + label_scatter = (; + color = clist, + markersize = ((x .+ 0.25) .* 40) ./ 5, # make adjustabel for users + ), + ) + else + eeg_topoplot!(axis, data, labels; positions, config.visual...) + end + + if config.layout.use_colorbar == true Colorbar(f[1, 2]; colormap = config.visual.colormap, config.colorbar...) end diff --git a/test/test_topoplot.jl b/test/test_topoplot.jl index 3fd2f7c14..b92531ede 100644 --- a/test/test_topoplot.jl +++ b/test/test_topoplot.jl @@ -25,6 +25,14 @@ end plot_topoplot(d1; positions = rand(Point2f, 10)) end +@testset "topoplot: highliht an electrode" begin + plot_topoplot(dat[:, 50, 1]; positions, high_chan = 2) +end + +@testset "topoplot: highliht several electrodes" begin + plot_topoplot(dat[:, 50, 1]; positions, high_chan = [1, 2]) +end + @testset "topoplot: no legend" begin plot_topoplot(dat[:, 50, 1]; positions = positions, layout = (; use_colorbar = false)) end @@ -58,3 +66,37 @@ end @testset "topoplot: positions through labels" begin plot_topoplot(dat[1:19, 50, 1]; labels = TopoPlots.CHANNELS_10_20) end + + +begin + function topoplot_indicator!(f, ix) + x = zeros(128) + x[ix] = 1 + clist = [:gray, :darkred][Int.(x .+ 1)] + ax = + f[1, 1] = Axis( + f, + width = Relative(0.4), + height = Relative(0.4), + halign = 1.2, + valign = 1, + aspect = 1, + ) + + UnfoldMakie.TopoPlots.eeg_topoplot!( + ax, + x; + positions = pos, + enlarge = 0.9, + label_scatter = (; + color = clist, + markersize = ((x .+ 0.25) .* 40) ./ 5, + strokewidth = 0, + ), + interpolation = UnfoldMakie.TopoPlots.NullInterpolator(), + ) + hidespines!(ax) + hidedecorations!(ax) + end + +end From 74ebd0c4f5e192bb90547c8d46353688d89cfae3 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 14:29:06 +0000 Subject: [PATCH 62/67] supportive_defaults + docs --- docs/literate/tutorials/topoplot.jl | 2 +- src/UnfoldMakie.jl | 1 + src/docstring_template.jl | 44 -------------------- src/plot_butterfly.jl | 4 +- src/plot_erpgrid.jl | 24 +++++------ src/plot_erpimage.jl | 8 ++-- src/plot_splines.jl | 12 +++--- src/plotconfig.jl | 10 +---- src/supportive_defaults.jl | 63 +++++++++++++++++++++++++++++ test/test_topoplot.jl | 34 ---------------- 10 files changed, 90 insertions(+), 112 deletions(-) create mode 100644 src/supportive_defaults.jl diff --git a/docs/literate/tutorials/topoplot.jl b/docs/literate/tutorials/topoplot.jl index ba3eb9f45..2e62370d7 100644 --- a/docs/literate/tutorials/topoplot.jl +++ b/docs/literate/tutorials/topoplot.jl @@ -16,7 +16,7 @@ using DataFrames # Data loading -dat, positions = TopoPlots.example_data() +dat, positions = TopoPlots.example_data(); # The size of `data` is 64×400×3. This means: # - 64 channels; diff --git a/src/UnfoldMakie.jl b/src/UnfoldMakie.jl index 6dc2213c1..4336b863b 100644 --- a/src/UnfoldMakie.jl +++ b/src/UnfoldMakie.jl @@ -48,6 +48,7 @@ end include("plotconfig.jl") include("docstring_template.jl") +include("supportive_defaults.jl") include("eeg_series.jl") include("plot_topoplotseries.jl") diff --git a/src/docstring_template.jl b/src/docstring_template.jl index 73a323996..86848601d 100644 --- a/src/docstring_template.jl +++ b/src/docstring_template.jl @@ -63,47 +63,3 @@ function _docstring(cfg_symb::Symbol) $(out) """ end - -function indiv_docstrings(cfg_symb::Symbol) - # plot_splines - if cfg_symb == :spline_default - return (; - ylabel = "Spline value", - xlabelvisible = false, - xticklabelsvisible = false, - ylabelvisible = true, - ) - elseif cfg_symb == :density_default - return (; xautolimitmargin = (0, 0), ylabel = "Density value") - elseif cfg_symb == :superlabel_default - return (; fontsize = 20, padding = (0, 0, 40, 0)) - # plot_butterfly - elseif cfg_symb == :topo_default - return (; - width = Relative(0.35), - height = Relative(0.35), - halign = 0.05, - valign = 0.95, - aspect = 1, - ) - # plot_erpimage - elseif cfg_symb == :meanplot_default - return (; - height = 100, - xlabel = "Time [s]", - xlabelpadding = 0, - xautolimitmargin = (0, 0), - ) - elseif cfg_symb == :sortplot_default - return (; ylabelvisible = true, yticklabelsvisible = false) - # plot_erpgrid - elseif cfg_symb == :hlines_grid_default - return (; color = :gray, linewidth = 0.5) - elseif cfg_symb == :vlines_grid_default - return (; color = :gray, linewidth = 0.5, ymin = 0.2, ymax = 0.8) - elseif cfg_symb == :lines_grid_default - return (; color = :deepskyblue3) - elseif cfg_symb == :labels_grid_default - return (; color = :gray, fontsize = 12, align = (:left, :top), space = :relative) - end -end diff --git a/src/plot_butterfly.jl b/src/plot_butterfly.jl index 7d668204c..33508f4af 100644 --- a/src/plot_butterfly.jl +++ b/src/plot_butterfly.jl @@ -31,7 +31,7 @@ Plot a Butterfly plot. - `topo_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of the topoplot axis.\\ To see all options just type `?Axis` in REPL.\\ - Defaults: $(indiv_docstrings(:topo_default)) + Defaults: $(supportive_defaults(:topo_default)) - `mapping = (;)`\\ For highlighting specific channels.\\ Example: `mapping = (; color = :highlight))`, where `:highlight` is variable with appopriate mapping. @@ -128,7 +128,7 @@ function plot_butterfly!( f_grid = f[1, 1] if (topolegend) - topo_axis = update_axis(indiv_docstrings(:topo_default); topo_axis...) + topo_axis = update_axis(supportive_defaults(:topo_default); topo_axis...) ix = unique(i -> plot_data[:, config.mapping.group[1]][i], 1:size(plot_data, 1)) topoplot_legend( diff --git a/src/plot_erpgrid.jl b/src/plot_erpgrid.jl index d49195e3a..a7bcdd83d 100644 --- a/src/plot_erpgrid.jl +++ b/src/plot_erpgrid.jl @@ -14,21 +14,21 @@ Plot an ERP image. - `ch_names::Vector{String}`\\ Vector with channel names. - `hlines_grid_axis::NamedTuple = (;)`\\ - Here you can flexibly change configurations of the hline axis.\\ + Here you can flexibly change configurations of the hlines on all subaxes.\\ To see all options just type `?hlines` in REPL.\\ - Defaults: $(indiv_docstrings(:hlines_grid_default)) + Defaults: $(supportive_defaults(:hlines_grid_default)) - `vlines_grid_axis::NamedTuple = (;)`\\ - Here you can flexibly change configurations of the vline axis.\\ + Here you can flexibly change configurations of the vlines on all subaxes.\\ To see all options just type `?vlines` in REPL.\\ - Defaults: $(indiv_docstrings(:vlines_grid_default)) + Defaults: $(supportive_defaults(:vlines_grid_default)) - `lines_grid_axis::NamedTuple = (;)`\\ - Here you can flexibly change configurations of the lines axis.\\ + Here you can flexibly change configurations of the lines on all subaxes.\\ To see all options just type `?lines` in REPL.\\ - Defaults: $(indiv_docstrings(:lines_grid_default)) + Defaults: $(supportive_defaults(:lines_grid_default)) - `labels_grid_axis::NamedTuple = (;)`\\ - Here you can flexibly change configurations of the labels axis.\\ + Here you can flexibly change configurations of the labels on all subaxes.\\ To see all options just type `?text` in REPL.\\ - Defaults: $(indiv_docstrings(:labels_grid_default)) + Defaults: $(supportive_defaults(:labels_grid_default)) ## Keyword arguments (kwargs) - `drawlabels::Bool = false`\\ @@ -93,7 +93,7 @@ function plot_erpgrid!( axlist = [] rel_zeropoint = argmin(abs.(times)) ./ length(times) labels_grid_axis = - update_axis(indiv_docstrings(:labels_grid_default); labels_grid_axis...) + update_axis(supportive_defaults(:labels_grid_default); labels_grid_axis...) for (ix, p) in enumerate(eachcol(positions)) x = p[1] y = p[2] @@ -112,10 +112,10 @@ function plot_erpgrid!( push!(axlist, ax) end hlines_grid_axis = - update_axis(indiv_docstrings(:hlines_grid_default); hlines_grid_axis...) + update_axis(supportive_defaults(:hlines_grid_default); hlines_grid_axis...) vlines_grid_axis = - update_axis(indiv_docstrings(:vlines_grid_default); vlines_grid_axis...) - lines_grid_axis = update_axis(indiv_docstrings(:lines_grid_default); lines_grid_axis...) + update_axis(supportive_defaults(:vlines_grid_default); vlines_grid_axis...) + lines_grid_axis = update_axis(supportive_defaults(:lines_grid_default); lines_grid_axis...) hlines!.(axlist, Ref([0.0]); hlines_grid_axis...) vlines!.(axlist, Ref([0.0]); vlines_grid_axis...) diff --git a/src/plot_erpimage.jl b/src/plot_erpimage.jl index 2cbd490e3..e08cb9388 100644 --- a/src/plot_erpimage.jl +++ b/src/plot_erpimage.jl @@ -34,11 +34,11 @@ Plot an ERP image. - `meanplot_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of meanplot.\\ To see all options just type `?Axis` in REPL.\\ - Defaults: $(indiv_docstrings(:meanplot_default)) + Defaults: $(supportive_defaults(:meanplot_default)) - `sortplot_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of meanplot.\\ To see all options just type `?Axis` in REPL.\\ - Defaults: $(indiv_docstrings(:sortplot_default)) + Defaults: $(supportive_defaults(:sortplot_default)) $(_docstring(:erpimage)) @@ -136,7 +136,7 @@ function ei_meanplot(ax, data, config, f, ga, times, meanplot_axis) ax.xticklabelsvisible = false trace = @lift(mean($data, dims = 2)[:, 1]) - meanplot_axis = update_axis(indiv_docstrings(:meanplot_default); meanplot_axis...) + meanplot_axis = update_axis(supportive_defaults(:meanplot_default); meanplot_axis...) axbottom = Axis( ga[5, 1:4]; @@ -163,7 +163,7 @@ function ei_sortvalue(sortvalues, f, ax, hm, config, sortval_xlabel, sortplot_ax error("`show_sortval` can not take `sortvalues` with all NaN-values") end gb = f[1, 3] = GridLayout() - sortplot_axis = update_axis(indiv_docstrings(:sortplot_default); sortplot_axis...) + sortplot_axis = update_axis(supportive_defaults(:sortplot_default); sortplot_axis...) axleft = Axis( gb[1:4, 1:5]; xlabel = sortval_xlabel, diff --git a/src/plot_splines.jl b/src/plot_splines.jl index d75a2d909..7041ad3a2 100644 --- a/src/plot_splines.jl +++ b/src/plot_splines.jl @@ -19,15 +19,15 @@ Dashed lines indicate spline knots. - `spline_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of spline subplots.\\ To see all options just type `?Axis` in REPL.\\ - Defaults: $(indiv_docstrings(:spline_default)) + Defaults: $(supportive_defaults(:spline_default)) - `density_axis::NamedTuple = (;)`\\ Here you can flexibly change configurations of density subplots.\\ To see all options just type `?Axis` in REPL.\\ - Defaults: $(indiv_docstrings(:density_default)) + Defaults: $(supportive_defaults(:density_default)) - `superlabel_config::NamedTuple = (;)`\\ Here you can flexibly change configurations of the Label on the top of the plot.\\ To see all options just type `?Label` in REPL.\\ - Defaults: $(indiv_docstrings(:superlabel_default)) + Defaults: $(supportive_defaults(:superlabel_default)) $(_docstring(:splines)) @@ -98,9 +98,9 @@ function plot_splines( end function supportive_axes_management(spline_axis, density_axis, superlabel_config) - spline_axis = update_axis(indiv_docstrings(:spline_default); spline_axis...) - density_axis = update_axis(indiv_docstrings(:density_default); density_axis...) + spline_axis = update_axis(supportive_defaults(:spline_default); spline_axis...) + density_axis = update_axis(supportive_defaults(:density_default); density_axis...) superlabel_config = - update_axis(indiv_docstrings(:superlabel_default); superlabel_config...) + update_axis(supportive_defaults(:superlabel_default); superlabel_config...) return spline_axis, density_axis, superlabel_config end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 84dee391a..34ee8affa 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -334,12 +334,4 @@ function config_kwargs!(cfg::PlotConfig; kwargs...) end end -""" - update_axis!(support_axis::NamedTuple; kwargs...) -Update values of `NamedTuple{key = value}`.\\ -Used for supportive axes to make users be able to flexibly change them. -""" -function update_axis(support_axis::NamedTuple; kwargs...) - support_axis = (; support_axis..., kwargs...) - return support_axis -end + diff --git a/src/supportive_defaults.jl b/src/supportive_defaults.jl new file mode 100644 index 000000000..b509968cd --- /dev/null +++ b/src/supportive_defaults.jl @@ -0,0 +1,63 @@ + +""" + supportive_defaults(cfg_symb::Symbol) + +Default configurations for the supporting axis. Similar to PlotConfig, but these configurations are not shared by all plots.\\ +Such supporting axes allow users to flexibly see defaults in docstrings and manipulate them using corresponding axes. + +For developers: to make them updateable in the function, use `update_axis`. +**Return value:** `NamedConfig`. +""" +function supportive_defaults(cfg_symb::Symbol) + # plot_splines + if cfg_symb == :spline_default + return (; + ylabel = "Spline value", + xlabelvisible = false, + xticklabelsvisible = false, + ylabelvisible = true, + ) + elseif cfg_symb == :density_default + return (; xautolimitmargin = (0, 0), ylabel = "Density value") + elseif cfg_symb == :superlabel_default + return (; fontsize = 20, padding = (0, 0, 40, 0)) + # plot_butterfly + elseif cfg_symb == :topo_default + return (; + width = Relative(0.35), + height = Relative(0.35), + halign = 0.05, + valign = 0.95, + aspect = 1, + ) + # plot_erpimage + elseif cfg_symb == :meanplot_default + return (; + height = 100, + xlabel = "Time [s]", + xlabelpadding = 0, + xautolimitmargin = (0, 0), + ) + elseif cfg_symb == :sortplot_default + return (; ylabelvisible = true, yticklabelsvisible = false) + # plot_erpgrid + elseif cfg_symb == :hlines_grid_default + return (; color = :gray, linewidth = 0.5) + elseif cfg_symb == :vlines_grid_default + return (; color = :gray, linewidth = 0.5, ymin = 0.2, ymax = 0.8) + elseif cfg_symb == :lines_grid_default + return (; color = :deepskyblue3) + elseif cfg_symb == :labels_grid_default + return (; color = :gray, fontsize = 12, align = (:left, :top), space = :relative) + end +end + +""" + update_axis(support_axis::NamedTuple; kwargs...) +Update values of `NamedTuple{key = value}`.\\ +Used for supportive axes to make users be able to flexibly change them. +""" +function update_axis(support_axis::NamedTuple; kwargs...) + support_axis = (; support_axis..., kwargs...) + return support_axis +end \ No newline at end of file diff --git a/test/test_topoplot.jl b/test/test_topoplot.jl index b92531ede..f9518fcb3 100644 --- a/test/test_topoplot.jl +++ b/test/test_topoplot.jl @@ -66,37 +66,3 @@ end @testset "topoplot: positions through labels" begin plot_topoplot(dat[1:19, 50, 1]; labels = TopoPlots.CHANNELS_10_20) end - - -begin - function topoplot_indicator!(f, ix) - x = zeros(128) - x[ix] = 1 - clist = [:gray, :darkred][Int.(x .+ 1)] - ax = - f[1, 1] = Axis( - f, - width = Relative(0.4), - height = Relative(0.4), - halign = 1.2, - valign = 1, - aspect = 1, - ) - - UnfoldMakie.TopoPlots.eeg_topoplot!( - ax, - x; - positions = pos, - enlarge = 0.9, - label_scatter = (; - color = clist, - markersize = ((x .+ 0.25) .* 40) ./ 5, - strokewidth = 0, - ), - interpolation = UnfoldMakie.TopoPlots.NullInterpolator(), - ) - hidespines!(ax) - hidedecorations!(ax) - end - -end From 9f2ef7249b24611fb1961477ae5981d787ea5a3c Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 14:34:13 +0000 Subject: [PATCH 63/67] format --- src/plot_erpgrid.jl | 3 ++- src/plotconfig.jl | 2 -- src/supportive_defaults.jl | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/plot_erpgrid.jl b/src/plot_erpgrid.jl index a7bcdd83d..fa994f9ff 100644 --- a/src/plot_erpgrid.jl +++ b/src/plot_erpgrid.jl @@ -115,7 +115,8 @@ function plot_erpgrid!( update_axis(supportive_defaults(:hlines_grid_default); hlines_grid_axis...) vlines_grid_axis = update_axis(supportive_defaults(:vlines_grid_default); vlines_grid_axis...) - lines_grid_axis = update_axis(supportive_defaults(:lines_grid_default); lines_grid_axis...) + lines_grid_axis = + update_axis(supportive_defaults(:lines_grid_default); lines_grid_axis...) hlines!.(axlist, Ref([0.0]); hlines_grid_axis...) vlines!.(axlist, Ref([0.0]); vlines_grid_axis...) diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 34ee8affa..ac1961aad 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -333,5 +333,3 @@ function config_kwargs!(cfg::PlotConfig; kwargs...) setfield!(cfg, k, merge(getfield(cfg, k), kwargs[k])) end end - - diff --git a/src/supportive_defaults.jl b/src/supportive_defaults.jl index b509968cd..2878ea1ab 100644 --- a/src/supportive_defaults.jl +++ b/src/supportive_defaults.jl @@ -9,7 +9,7 @@ For developers: to make them updateable in the function, use `update_axis`. **Return value:** `NamedConfig`. """ function supportive_defaults(cfg_symb::Symbol) - # plot_splines + # plot_splines if cfg_symb == :spline_default return (; ylabel = "Spline value", @@ -60,4 +60,4 @@ Used for supportive axes to make users be able to flexibly change them. function update_axis(support_axis::NamedTuple; kwargs...) support_axis = (; support_axis..., kwargs...) return support_axis -end \ No newline at end of file +end From c465e86b47f0341c59572d888f0f68f826d0e769 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Mon, 23 Sep 2024 19:42:52 +0000 Subject: [PATCH 64/67] upd Readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bb492988..62a88e40c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A toolbox for visualizations of EEG/ERP data and Unfold.jl models. Based on the [Unfold](https://github.com/unfoldtoolbox/unfold.jl/) and [Makie](https://makie.juliaplots.org/stable/), it grants users high performance, and highly customizable plots. -We currently support: +We currently support 9 general ERP plots: - ![icon_erpplot_20px](https://github.com/unfoldtoolbox/UnfoldMakie.jl/assets/10183650/22c8472d-df78-46d7-afe8-e1e4e7b04313) ERP plots @@ -37,9 +37,11 @@ ERP images Channel images - ![icon_parallel_20px](https://github.com/unfoldtoolbox/UnfoldMakie.jl/assets/10183650/dab097c3-bcd6-4405-a44b-71cbe3e5fac9) Parallel coordinates -- Design matrices - Circular topoplots +And 2 Unfold-specific plots: +- Design matrices +- Splines plot ## Install From 38c45f9c6c21946fcbf3e36a9722c1cc6ecf80c2 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 24 Sep 2024 09:36:08 +0000 Subject: [PATCH 65/67] upd Readme2 --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62a88e40c..8a85c4828 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,13 @@ | | ||||| A toolbox for visualizations of EEG/ERP data and Unfold.jl models. -Based on the [Unfold](https://github.com/unfoldtoolbox/unfold.jl/) and [Makie](https://makie.juliaplots.org/stable/), it grants users high performance, and highly customizable plots. + +Based on three libraries +- [Unfold](https://github.com/unfoldtoolbox/unfold.jl/) - for performing deconvolution regression; +- [Makie](https://makie.juliaplots.org/stable/) - very flexible visualisation library ([Maki-e](https://en.wikipedia.org/wiki/Maki-e) means "visualisation" on Japanese); +- [Algebra of Graphics](https://github.com/MakieOrg/AlgebraOfGraphics.jl) - Makie-based visualisation library, allowing flexible mapping. + +This grants users high performance, and highly customizable plots. We currently support 9 general ERP plots: @@ -115,8 +121,8 @@ If you use these visualizations, please cite: Benedikt Ehinger
Benedikt Ehinger

🐛 💻 📖 🤔 🚇 🚧 💬 👀 ⚠️ - Quantum
Daniel Baumgartner

💻 📖 Vladimir Mikheev
Vladimir Mikheev

🐛 💻 📖 🤔 🚧 👀 ⚠️ + Quantum
Daniel Baumgartner

💻 📖 NiklasMGaertner
Niklas Gärtner

💻 📖 SorenDoring
Soren Doring

💻 📖 lokmanfl
Fadil Furkan Lokman

💻 📖 From 9aa472b766aaf804ab509e7d8677a46dd5d33891 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 24 Sep 2024 12:02:34 +0000 Subject: [PATCH 66/67] the last edit --- src/supportive_defaults.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/supportive_defaults.jl b/src/supportive_defaults.jl index 2878ea1ab..f6427141c 100644 --- a/src/supportive_defaults.jl +++ b/src/supportive_defaults.jl @@ -6,7 +6,7 @@ Default configurations for the supporting axis. Similar to PlotConfig, but these Such supporting axes allow users to flexibly see defaults in docstrings and manipulate them using corresponding axes. For developers: to make them updateable in the function, use `update_axis`. -**Return value:** `NamedConfig`. +**Return value:** `NamedTuple`. """ function supportive_defaults(cfg_symb::Symbol) # plot_splines From 6d3dae62d44f768098b421157013f77208bc0b01 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Tue, 24 Sep 2024 12:03:15 +0000 Subject: [PATCH 67/67] version up --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 991bfaba1..d65c797c9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "UnfoldMakie" uuid = "69a5ce3b-64fb-4f22-ae69-36dd4416af2a" authors = ["Vladimir Mikheev", "Daniel Baumgartner", "Sören Döring", "Niklas Gärtner", "Furkan Lokman", "Benedikt Ehinger"] -version = "0.5.7" +version = "0.5.8" [deps] AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"