From 7286bedaaf28d15560fec08607fcaf18edc8efa7 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 16 Nov 2023 16:03:51 +0000 Subject: [PATCH] upd and tests for topopositions_to_color --- docs/src/how_to/position2color.md | 11 +++++++---- src/plot_parallelcoordinates.jl | 12 ++++++------ src/plotconfig.jl | 4 ++-- test/test_butterfly.jl | 31 +++++++++++++++++++++++++++---- test/test_erp.jl | 29 ++++++++++++++++++++++++++++- test/test_pp.jl | 18 ------------------ 6 files changed, 70 insertions(+), 35 deletions(-) delete mode 100644 test/test_pp.jl diff --git a/docs/src/how_to/position2color.md b/docs/src/how_to/position2color.md index 44daa3fad..2f51b5c6b 100644 --- a/docs/src/how_to/position2color.md +++ b/docs/src/how_to/position2color.md @@ -21,17 +21,20 @@ We can switch the colorscale of the position-map, by giving a function that maps ### Similar to MNE ```@example main -plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction = pos -> UnfoldMakie.posToColorRGB(pos))) +plot_butterfly(results; + positions=positions, + topopositions_to_color = pos -> UnfoldMakie.posToColorRGB(pos) +) ``` ### HSV-Space ```@example main -plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction=UnfoldMakie.posToColorHSV)) +plot_butterfly(results; positions=positions, topopositions_to_color=UnfoldMakie.posToColorHSV) ``` ### Uniform Color To highlight the flexibility, we can also make all lines `gray`, or any other arbitrary color, or function of electrode-`position`. + ```@example main -using Colors -plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction = x -> Colors.RGB(0.5))) +plot_butterfly(results; positions=positions, topopositions_to_color = x -> Colors.RGB(0.5)) ``` \ No newline at end of file diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index 4b5a69cd2..1551a0e29 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -12,12 +12,12 @@ Plot a PCP (parallel coordinates plot). PCP has problems with size changes of the view window. By adapting the padding, aspect ratio and tick label size in px for a new use case, the PCP can even be added into a complex figures. -- `pc_aspect_ratio` (default: `0.55`) - -- `pc_right_padding` (default: `15`) - -- `pc_left_padding` (default: `25`) - -- `pc_top_padding` (default: `26`) - -- `pc_bottom_padding` (default: `16`) - -- `pc_tick_label_size` (default: `14`) - +- `pc_aspect_ratio` (default: `0.55`) - +- `pc_right_padding` (default: `15`) - +- `pc_left_padding` (default: `25`) - +- `pc_top_padding` (default: `26`) - +- `pc_bottom_padding` (default: `16`) - +- `pc_tick_label_size` (default: `14`) - $(_docstring(:paracoord)) diff --git a/src/plotconfig.jl b/src/plotconfig.jl index f7b528201..2f0decd99 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -65,9 +65,9 @@ function config_kwargs!(cfg::PlotConfig; kwargs...) """ Keyword argument specification (kwargs...) Specified config groups must be NamedTuples', but $(keys(kwargs)[.!is_namedtuple]) was not. Maybe you forgot the semicolon (;) at the beginning of your specification? Compare these strings: - plot_example(...; layout = (; showColorbar=true)) + plot_example(...; layout = (; use_colorbar=true)) - plot_example(...; layout = (showColorbar=true)) + plot_example(...; layout = (use_colorbar=true)) The first is correct and creates a NamedTuple as required. The second is wrong and its call is ignored.""") list = fieldnames(PlotConfig)#[:layout,:visual,:mapping,:legend,:colorbar,:axis] diff --git a/test/test_butterfly.jl b/test/test_butterfly.jl index 1b786556e..cfcabc8fc 100644 --- a/test/test_butterfly.jl +++ b/test/test_butterfly.jl @@ -1,13 +1,14 @@ +include("../docs/example_data.jl") +data, pos = example_data("TopoPlots.jl") +results, positions = example_data("TopoPlots.jl") +using Colors + @testset "basic" begin - include("../docs/example_data.jl") - data, pos = example_data("TopoPlots.jl") plot_butterfly(data; positions = pos) end @testset "topomarkersize change" begin - include("../docs/example_data.jl") - data, pos = example_data("TopoPlots.jl") plot_butterfly( data; positions = pos, @@ -18,4 +19,26 @@ end end +@testset "changing color from ROMA to gray" begin + plot_butterfly( + results; + positions = positions, + topopositions_to_color = x -> Colors.RGB(0.5) + ) +end +@testset "changing color from ROMA to HSV" begin + plot_butterfly( + results; + positions = positions, + topopositions_to_color=UnfoldMakie.posToColorHSV + ) +end + +@testset "changing color from ROMA to RGB" begin + plot_butterfly( + results; + positions = positions, + topopositions_to_color = pos -> UnfoldMakie.posToColorRGB(pos) + ) +end diff --git a/test/test_erp.jl b/test/test_erp.jl index 498b21a33..f7549c9ee 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -19,7 +19,7 @@ end -@testset "basic with res_effects" begin +@testset "basic with res_effects without colorbar" begin data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) data = reshape(data, (1, size(data)...)) f = @formula 0 ~ 1 + condition + continuous @@ -46,6 +46,33 @@ end ) end +@testset "basic with res_effects" begin + data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) + data = reshape(data, (1, size(data)...)) + f = @formula 0 ~ 1 + condition + continuous + se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true) + + m = fit( + UnfoldModel, + Dict(Any => (f, range(0, step = 1 / 100, length = size(data, 2)))), + evts, + data, + solver = se_solver, + ) + results = coeftable(m) + res_effects = effects(Dict(:continuous => -5:0.5:5), m) + + # ## Plot the results + plot_erp( + res_effects; + mapping = (; y = :yhat, color = :continuous, group = :continuous), + legend = (; nbanks = 2), + layout = (; legend_position = :right, show_legend = true), + categorical_color = false, + categorical_group = true, + ) +end + @testset "erp plot in GridLayout" begin f = Figure(resolution=(1200, 1400)) diff --git a/test/test_pp.jl b/test/test_pp.jl deleted file mode 100644 index 4e9d6de03..000000000 --- a/test/test_pp.jl +++ /dev/null @@ -1,18 +0,0 @@ - -@testset "Figure, 3 channels, 1 condition" begin - include("../docs/example_data.jl") - results_plot, positions = example_data(); - plot_parallelcoordinates(results_plot, [5, 3, 2]; # this selects channel 5,3 & 2 - mapping = (color = :coefname, y = :estimate)) -end - - -@testset "GridPosition" begin - uf_5chan = example_data("UnfoldLinearModelMultiChannel") - d_singletrial, _ = UnfoldSim.predef_eeg(; return_epoched=true) - - f = Figure() - plot_parallelcoordinates!(f[1, 1], uf_5chan, [1, 2, 3, 4, 5]; - mapping=(; color=:coefname), layout=(; legend_position=:bottom)) - f -end \ No newline at end of file