From aab63d08766a3fae036198cce028dfed42ce2a72 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 16 Nov 2023 14:56:27 +0000 Subject: [PATCH] plotconfig arguments --- docs/literate/tutorials/erp.jl | 2 +- docs/src/how_to/mult_vis_in_fig.md | 5 +++-- src/docstringtemplate.jl | 6 ++---- src/layout_helper.jl | 16 ++++++++-------- src/plot_erpimage.jl | 4 ++-- src/plot_parallelcoordinates.jl | 2 +- src/plot_topoplot.jl | 2 +- src/plot_topoplotseries.jl | 4 ++-- src/plotconfig.jl | 18 +++++++++--------- test/runtests.jl | 12 ++++++++---- test/test_complexplots.jl | 8 ++++---- test/test_erp.jl | 2 +- test/test_pcp.jl | 2 +- test/test_pp.jl | 2 +- 14 files changed, 44 insertions(+), 41 deletions(-) diff --git a/docs/literate/tutorials/erp.jl b/docs/literate/tutorials/erp.jl index 15b5f370f..e88a08963 100644 --- a/docs/literate/tutorials/erp.jl +++ b/docs/literate/tutorials/erp.jl @@ -62,7 +62,7 @@ plot_erp( res_effects; mapping = (; y = :yhat, color = :continuous, group = :continuous), legend = (; nbanks = 2), - layout = (; showLegend = true, legendPosition = :right), + layout = (; showLegend = true, legend_position = :right), categorical_color = false, categorical_group = true, ) diff --git a/docs/src/how_to/mult_vis_in_fig.md b/docs/src/how_to/mult_vis_in_fig.md index 1c67de6a8..1df4c4f51 100644 --- a/docs/src/how_to/mult_vis_in_fig.md +++ b/docs/src/how_to/mult_vis_in_fig.md @@ -76,9 +76,10 @@ 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), legend=(; nbanks=2), - layout=(; showLegend=true, legendPosition=:right)) + layout=(; show_legend=true, legend_position=:right)) -plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legendPosition=:bottom)) +plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), + layout=(; legend_position=:bottom)) plot_erpimage!(f[1, 4:5], times, d_singletrial) plot_circulareegtopoplot!(f[3:4, 4:5], d_topo[in.(d_topo.time, Ref(-0.3:0.1:0.5)), :]; diff --git a/src/docstringtemplate.jl b/src/docstringtemplate.jl index 921713b49..aea66ab9d 100644 --- a/src/docstringtemplate.jl +++ b/src/docstringtemplate.jl @@ -36,16 +36,14 @@ function _docstring(cfgsymb::Symbol) return """## Shared plot configuration options The shared plot options can be used as follows: - `type=(; key=value,...))` - for example `plot_x(..., layout=(showLegend=true, legendPosition=:right))`. Multiple defaults will be cycled until match. + `type=(; key=value,...))` - for example `plot_x(..., layout=(show_legend=true, legend_position=:right))`. + Multiple defaults will be cycled until match. $(out) """ end - - - """ $(TYPEDSIGNATURES) $(_docstring(:erp)) diff --git a/src/layout_helper.jl b/src/layout_helper.jl index 781f1a47a..fe21a1540 100644 --- a/src/layout_helper.jl +++ b/src/layout_helper.jl @@ -4,25 +4,25 @@ function applyLayoutSettings!(config::PlotConfig; fig=nothing, hm=nothing, ax = current_axis() end - if (config.layout.showLegend) + if (config.layout.show_legend) if isnothing(fig) @error "Legend needs figure parameter" else - # set f[] position depending on legendPosition - legendPosition = config.layout.legendPosition == :right ? fig[1:plotArea[1], plotArea[2]+1] : fig[plotArea[1]+1, 1:plotArea[2]] + # 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) if isnothing(hm) - Colorbar(legendPosition; colormap=config.visual.colormap, config.colorbar...) + Colorbar(legend_position; colormap=config.visual.colormap, config.colorbar...) else - Colorbar(legendPosition, hm; config.colorbar...) + Colorbar(legend_position, hm; config.colorbar...) end else - Legend(legendPosition, ax; config.legend...) + Legend(legend_position, ax; config.legend...) end else - legend!(legendPosition, drawing; config.legend...) - colorbar!(legendPosition, drawing; config.colorbar...) + legend!(legend_position, drawing; config.legend...) + colorbar!(legend_position, drawing; config.colorbar...) end end end diff --git a/src/plot_erpimage.jl b/src/plot_erpimage.jl index b00ec64d1..ad2607318 100644 --- a/src/plot_erpimage.jl +++ b/src/plot_erpimage.jl @@ -81,14 +81,14 @@ function plot_erpimage!( subConfig = deepcopy(config) config_kwargs!( subConfig; - layout = (; showLegend = false), + layout = (; show_legend = false), axis = (; ylabel = config.colorbar.label === nothing ? "" : config.colorbar.label ), ) axisOffset = - (config.layout.showLegend && config.layout.legendPosition == :bottom) ? 1 : 0 + (config.layout.show_legend && config.layout.legend_position == :bottom) ? 1 : 0 subAxis = Axis(f[5+axisOffset, 1]; subConfig.axis...) lines!(subAxis, mean(plot, dims = 2)[:, 1]) diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index 3d23dc066..116ae70b8 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -120,7 +120,7 @@ function plot_parallelcoordinates!( labelfont = "Arial", ticklabelfont = "Arial", spinevisible = true, - labelrotation = 0.0, + label_rotation = 0.0, ticklabelsize = tick_label_size, minorticks = IntervalsBetween(2), endpoints = Point2f[(x_values[i], bottom_padding), (x_values[i], y_values[i])], diff --git a/src/plot_topoplot.jl b/src/plot_topoplot.jl index 56ad42c29..166925157 100644 --- a/src/plot_topoplot.jl +++ b/src/plot_topoplot.jl @@ -45,7 +45,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,showLegend=false)) + config_kwargs!(config, layout = (; use_colorbar=false, show_legend=false)) else config_kwargs!(config, colorbar = (; limits = clims)) end diff --git a/src/plot_topoplotseries.jl b/src/plot_topoplotseries.jl index d9c826cc1..7f7c7eb9c 100644 --- a/src/plot_topoplotseries.jl +++ b/src/plot_topoplotseries.jl @@ -79,7 +79,7 @@ function plot_topoplotseries!( colorrange = d.colorrange, height = config.colorbar.height, flipaxis = config.colorbar.flipaxis, - labelrotation = config.colorbar.labelrotation, + label_rotation = config.colorbar.label_rotation, label = config.colorbar.label, ) else @@ -91,7 +91,7 @@ function plot_topoplotseries!( colorrange = d.colorrange, height = config.colorbar.height, flipaxis = config.colorbar.flipaxis, - labelrotation = config.colorbar.labelrotation, + label_rotation = config.colorbar.label_rotation, label = config.colorbar.label, ) end diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 8ed720e18..3c7ec3af5 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -27,8 +27,8 @@ function PlotConfig()# defaults (;), #figure (;), # axis (; # layout - showLegend = true, - legendPosition = :right, + show_legend = true, + legend_position = :right, xlabelFromMapping = :x, ylabelFromMapping = :y, use_colorbar = false, @@ -90,7 +90,7 @@ function PlotConfig(T::Val{:circeegtopo}) config_kwargs!( cfg; - layout = (; showLegend = false), + layout = (; show_legend = false), colorbar = (; label = "Voltage [µV]", colormap = Reverse(:RdBu)), mapping = (;), axis = (; @@ -123,7 +123,7 @@ function PlotConfig(T::Val{:topoplot}) config_kwargs!( cfg; layout = ( - showLegend = true, + show_legend = true, xlabelFromMapping = nothing, ylabelFromMapping = nothing, use_colorbar = true, @@ -154,7 +154,7 @@ function PlotConfig(T::Val{:topoplotseries}) colorbar = (; height = 300, # why even should i made it manually? flipaxis = true, - labelrotation = 4.7, + label_rotation = 4.7, label = "Voltage [µV]" ), visual = (; @@ -182,10 +182,10 @@ function PlotConfig(T::Val{:butterfly}) cfg = PlotConfig(:erp) config_kwargs!( cfg; - layout = (; showLegend = false), + layout = (; show_legend = false), mapping = (; color = (:channel, :channels, :trial, :trials), - positions = (:pos, :positions, :position, :topoPositions, :x, nothing), + positions = (:pos, :positions, :position, :topo_positions, :x, nothing), labels = (:labels, :label, :topoLabels, :sensor, nothing), ), ) @@ -196,7 +196,7 @@ function PlotConfig(T::Val{:erp}) config_kwargs!( cfg; mapping = (; color = (:color, :coefname, nothing)), - layout = (; showLegend = true, hidespines = (:r, :t)), + layout = (; show_legend = true, hidespines = (:r, :t)), legend = (; framevisible = false), ) @@ -207,7 +207,7 @@ function PlotConfig(T::Val{:erpimage}) config_kwargs!( cfg; layout = (; use_colorbar = true), - colorbar = (; label = "Voltage [µV]", labelrotation = 4.7), + colorbar = (; label = "Voltage [µV]", label_rotation = 4.7), axis = (xlabel = "Time", ylabel = "Sorted trials"), visual = (; colormap = Reverse("RdBu")), ) diff --git a/test/runtests.jl b/test/runtests.jl index 1b2d36f83..e85af7104 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,10 +15,6 @@ end include("test_butterfly.jl") end -@testset "Topoplot series" begin - include("test_toposeries.jl") -end - @testset "ERP Image" begin include("test_erpimage.jl") end @@ -27,6 +23,14 @@ end include("test_topoplot.jl") end +@testset "Topoplot series" begin + include("test_toposeries.jl") +end + +@testset "Parallel coordinates plot" begin + include("test_pcp.jl") +end + @testset "Circular EEG topoplot" begin include("test_plot_circulareegtopoplot.jl") end diff --git a/test/test_complexplots.jl b/test/test_complexplots.jl index 9a3e9451a..b570e0d14 100644 --- a/test/test_complexplots.jl +++ b/test/test_complexplots.jl @@ -43,7 +43,7 @@ plot_erpgrid!(ge, data[:, :, 1], positions) plot_erpimage!(gf, times, d_singletrial) plot_parallelcoordinates!(gh, uf_5chan, [1, 2, 3, 4, 5]; - mapping=(; color=:coefname), layout=(; legendPosition=:bottom), legend=(; tellwidth =false)) + mapping=(; color=:coefname), layout=(; legend_position=:bottom), legend=(; tellwidth =false)) for (label, layout) in zip(["A", "B", "C", "D", "E", "F", "G", "H"], [ga, gb, gc, gd, ge, gf, gg, gh]) Label(layout[1, 1, TopLeft()], label, @@ -89,7 +89,7 @@ end plot_erpimage!(f[3, 2], times, d_singletrial) plot_parallelcoordinates!(f[4, 2], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), - layout=(; legendPosition=:bottom), legend=(; tellwidth =false)) + layout=(; legend_position=:bottom), legend=(; tellwidth =false)) for (label, layout) in zip(["A", "B", "C", "D", "E", "F", "G", "H"], [f[1, 1], f[1, 2], f[2, 1], f[2, 2], f[3, 1], f[3, 2], f[4, 1], f[4, 2]]) @@ -140,9 +140,9 @@ end plot_erp!(f[2, 4:5], res_effects; categorical_color=false, categorical_group=true, mapping=(; y=:yhat, color=:continuous, group=:continuous), legend=(; nbanks=2), - layout=(; showLegend=true, legendPosition=:right)) + layout=(; show_legend=true, legend_position=:right)) - plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legendPosition=:bottom)) + plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legend_position=:bottom)) plot_erpimage!(f[1, 4:5], times, d_singletrial) plot_circulareegtopoplot!(f[3:4, 4:5], d_topo[in.(d_topo.time, Ref(-0.3:0.1:0.5)), :]; diff --git a/test/test_erp.jl b/test/test_erp.jl index 78fd36833..498b21a33 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -40,7 +40,7 @@ end res_effects; mapping = (; y = :yhat, color = :continuous, group = :continuous), legend = (; nbanks = 2), - layout = (; legendPosition = :right, showLegend = false), + layout = (; legend_position = :right, show_legend = false), categorical_color = false, categorical_group = true, ) diff --git a/test/test_pcp.jl b/test/test_pcp.jl index 581e808e1..4e9d6de03 100644 --- a/test/test_pcp.jl +++ b/test/test_pcp.jl @@ -13,6 +13,6 @@ end f = Figure() plot_parallelcoordinates!(f[1, 1], uf_5chan, [1, 2, 3, 4, 5]; - mapping=(; color=:coefname), layout=(; legendPosition=:bottom)) + mapping=(; color=:coefname), layout=(; legend_position=:bottom)) f end \ No newline at end of file diff --git a/test/test_pp.jl b/test/test_pp.jl index 581e808e1..4e9d6de03 100644 --- a/test/test_pp.jl +++ b/test/test_pp.jl @@ -13,6 +13,6 @@ end f = Figure() plot_parallelcoordinates!(f[1, 1], uf_5chan, [1, 2, 3, 4, 5]; - mapping=(; color=:coefname), layout=(; legendPosition=:bottom)) + mapping=(; color=:coefname), layout=(; legend_position=:bottom)) f end \ No newline at end of file