diff --git a/docs/src/tutorials/topoplotseries.md b/docs/src/tutorials/topoplotseries.md index ff88fe472..03ab94302 100644 --- a/docs/src/tutorials/topoplotseries.md +++ b/docs/src/tutorials/topoplotseries.md @@ -1,4 +1,4 @@ -# [Topo Plot SeriesVisualization](@id tpseries_vis) +# [Topoplot Series Visualization](@id tpseries_vis) ## Include used Modules @@ -10,9 +10,9 @@ using DataFrames using CairoMakie using TopoPlots ``` -## Plot Topo Plots Series +## Plot Topoplot Series -### Giving the Data +### Example data In case you do not already have data, you can get example data from the `TopoPlots` module. You can do it like this: @@ -26,11 +26,25 @@ nothing #hide Δbin = 80 plot_topoplotseries(df, Δbin; positions = positions) ``` +### Arguments usage -Without colorbar: +- `f::Union{GridPosition, GridLayout, Figure}`: Figure or GridPosition that the plot should be drawn into. +- `data::DataFrame`: DataFrame with data, needs a `time` column. +- `Δbin::Real`: A number for how large one time bin should be. Δbin is in units of the `data.time` column. + +### Key arguments +- `combinefun` (default: `mean`) - can be used to specify how the samples within `Δbin` are combined. +- `rasterize_heatmaps` (default: `true`) - enforce rasterization of the plot heatmap when saving in svg format. + This has the benefit that all lines/points are vectors, except the interpolated heatmap. + This is typically what you want, otherwise you get ~500x500 vectors per topoplot, which makes everything super slow. +- `col_labels`, `row_labels` - shows column and row labels. +- labels (default: `nothing`) - . +- positions (default: `nothing`) - . + +Disabling colorbar: ```@example main -plot_topoplotseries(df, Δbin; positions=positions, layout = (; useColorbar=false)) +plot_topoplotseries(df, Δbin; positions=positions, layout = (; use_colorbar=false)) ``` ### Positions diff --git a/src/layout_helper.jl b/src/layout_helper.jl index 2415c88b2..781f1a47a 100644 --- a/src/layout_helper.jl +++ b/src/layout_helper.jl @@ -11,7 +11,7 @@ function applyLayoutSettings!(config::PlotConfig; fig=nothing, hm=nothing, # 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]] if isnothing(drawing) - if (config.layout.useColorbar) + if (config.layout.use_colorbar) if isnothing(hm) Colorbar(legendPosition; colormap=config.visual.colormap, config.colorbar...) else diff --git a/src/plot_designmatrix.jl b/src/plot_designmatrix.jl index a72fda643..50d761fc0 100644 --- a/src/plot_designmatrix.jl +++ b/src/plot_designmatrix.jl @@ -12,11 +12,11 @@ Plot a designmatrix. - `standardize_data` (bool,`true`): indicates whether the data is standardized by pointwise division of the data with its sampled standard deviation. - `sort_data` (bool, `true`): indicates whether the data is sorted; using sortslices() of Base Julia. - `xticks` (`nothing`): returns the number of labels on the x-axis. Behavior is set in the configuration: - - xticks = 0: no labels are placed. - - xticks = 1: first possible label is placed. - - xticks = 2: first and last possible labels are placed. - - 2 < xticks < `number of labels`: equally distribute the labels. - - xticks ≥ `number of labels`: all labels are placed. + - `xticks` = 0: no labels are placed. + - `xticks` = 1: first possible label is placed. + - `xticks` = 2: first and last possible labels are placed. + - 2 < `xticks` < `number of labels`: equally distribute the labels. + - `xticks` ≥ `number of labels`: all labels are placed. $(_docstring(:designmat)) diff --git a/src/plot_erpimage.jl b/src/plot_erpimage.jl index fa4bb3495..b00ec64d1 100644 --- a/src/plot_erpimage.jl +++ b/src/plot_erpimage.jl @@ -13,7 +13,7 @@ Plot an ERP image. ## Keyword Arguments - `erpblur` (Number, `10`) - Number indicating how much blur is applied to the image; using Gaussian blur of the ImageFiltering module. Non-Positive values deactivate the blur. -- `sortix` (): . +- `sortix` (default: `nothing`): . - `sortvalues` (bool, `false`) - parameter over which plot will be sorted. Using sortperm() of Base Julia. - sortperm() computes a permutation of the array's indices that puts the array into sorted order. - `meanplot`: (bool, `false`) - Indicating whether the plot should add a line plot below the ERP image, showing the mean of the data. diff --git a/src/plot_topoplot.jl b/src/plot_topoplot.jl index 24dceaccd..56ad42c29 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 = (; useColorbar=false,showLegend=false)) + config_kwargs!(config, layout = (; use_colorbar=false,showLegend=false)) else config_kwargs!(config, colorbar = (; limits = clims)) end diff --git a/src/plot_topoplotseries.jl b/src/plot_topoplotseries.jl index 2758f05e6..d9c826cc1 100644 --- a/src/plot_topoplotseries.jl +++ b/src/plot_topoplotseries.jl @@ -1,19 +1,21 @@ """ - plot_topoplotseries!(f::Union{GridPosition, GridLayout, Figure}, plotData::DataFrame, Δbin::Real; kwargs...) - plot_topoplotseries!(plotData::DataFrame, Δbin::Real; kwargs...) + plot_topoplotseries!(f::Union{GridPosition, GridLayout, Figure}, data::DataFrame, Δbin::Real; kwargs...) + plot_topoplotseries!(data::DataFrame, Δbin::Real; kwargs...) Multiple miniature topoplots in regular distances ## Arguments: -- `f::Union{GridPosition, GridLayout, Figure}`: Figure or GridPosition that the plot should be drawn into -- `plotData::DataFrame`: DataFrame with data, needs a `time` column -- `Δbin::Real`: A number for how large one bin should be. Δbin is in units of the `plotData.time` column -- `combinefun` (default `mean`) can be used to specify how the samples within `Δbin` are combined. -- `rasterize_heatmaps` (deault `true`) - enforce rasterization of the plot heatmap when saving in svg format. - This has the benefit that all lines/points are vectors, except the interpolated heatmap. - This is typically what you want, because else you get ~500x500 vectors per topoplot, which makes everything super slow. +- `f::Union{GridPosition, GridLayout, Figure}`: Figure or GridPosition that the plot should be drawn into. +- `data::DataFrame`: DataFrame with data, needs a `time` column. +- `Δbin::Real`: A number for how large one time bin should be. Δbin is in units of the `data.time` column. +- `combinefun` (default: `mean`) - can be used to specify how the samples within `Δbin` are combined. +- `rasterize_heatmaps` (default: `true`) - enforce rasterization of the plot heatmap when saving in svg format. + This has the benefit that all lines/points are vectors, except the interpolated heatmap. + This is typically what you want, otherwise you get ~500x500 vectors per topoplot, which makes everything super slow. - `col_labels`, `row_labels` - shows column and row labels. +- labels (default: `nothing`) - . +- positions (default: `nothing`) - . $(_docstring(:topoplotseries)) @@ -21,12 +23,12 @@ $(_docstring(:topoplotseries)) The input `f` """ -plot_topoplotseries(plotData::DataFrame, Δbin::Real; kwargs...) = - plot_topoplotseries!(Figure(), plotData, Δbin; kwargs...) +plot_topoplotseries(data::DataFrame, Δbin::Real; kwargs...) = + plot_topoplotseries!(Figure(), data, Δbin; kwargs...) function plot_topoplotseries!( f::Union{GridPosition,GridLayout,Figure}, - plotData::DataFrame, + data::DataFrame, Δbin; positions = nothing, labels = nothing, @@ -40,21 +42,21 @@ function plot_topoplotseries!( config = PlotConfig(:topoplotseries) config_kwargs!(config; kwargs...) - plotData = deepcopy(plotData) + data = deepcopy(data) # resolve columns with data - config.mapping = resolveMappings(plotData, config.mapping) + config.mapping = resolveMappings(data, config.mapping) positions = getTopoPositions(; positions = positions, labels = labels) - if "label" ∉ names(plotData) - plotData.label = plotData.channel + if "label" ∉ names(data) + data.label = data.channel end ftopo, axlist = eeg_topoplot_series!( f, - plotData, + data, Δbin; y = config.mapping.y, label = :label, @@ -68,7 +70,7 @@ function plot_topoplotseries!( config.visual..., ) - if config.layout.useColorbar + if config.layout.use_colorbar if typeof(ftopo) == Figure d = ftopo.content[1].scene.plots[1] Colorbar( diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 06efc553c..8ed720e18 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -31,7 +31,7 @@ function PlotConfig()# defaults legendPosition = :right, xlabelFromMapping = :x, ylabelFromMapping = :y, - useColorbar = false, + use_colorbar = false, ), (#maping x = (:time,), @@ -126,7 +126,7 @@ function PlotConfig(T::Val{:topoplot}) showLegend = true, xlabelFromMapping = nothing, ylabelFromMapping = nothing, - useColorbar = true, + use_colorbar = true, hidespines = (), hidedecorations = (), ), @@ -150,7 +150,7 @@ function PlotConfig(T::Val{:topoplotseries}) cfg = PlotConfig(:topoplot) config_kwargs!( cfg, - layout = (useColorbar = true,), + layout = (use_colorbar = true,), colorbar = (; height = 300, # why even should i made it manually? flipaxis = true, @@ -169,7 +169,7 @@ function PlotConfig(T::Val{:designmat}) config_kwargs!( cfg; layout = (; - useColorbar = true, + use_colorbar = true, xlabelFromMapping = nothing, ylabelFromMapping = nothing, ), @@ -206,7 +206,7 @@ function PlotConfig(T::Val{:erpimage}) cfg = PlotConfig() config_kwargs!( cfg; - layout = (; useColorbar = true), + layout = (; use_colorbar = true), colorbar = (; label = "Voltage [µV]", labelrotation = 4.7), axis = (xlabel = "Time", ylabel = "Sorted trials"), visual = (; colormap = Reverse("RdBu")), diff --git a/test/test_all.jl b/test/test_all.jl deleted file mode 100644 index d87c87623..000000000 --- a/test/test_all.jl +++ /dev/null @@ -1,153 +0,0 @@ -@testset "8 plots" begin - f = Figure(resolution=(1200, 1400)) - ga = f[1, 1] = GridLayout() - gc = f[2, 1] = GridLayout() - ge = f[3, 1] = GridLayout() - gg = f[4, 1] = GridLayout() - geh = f[1:4, 2] = GridLayout() - gb = geh[1, 1] = GridLayout() - gd = geh[2, 1] = GridLayout() - gf = geh[3, 1] = GridLayout() - gh = geh[4, 1] = GridLayout() - - include("../docs/example_data.jl") - d_topo, pos = example_data("TopoPlots.jl") - uf_deconv = example_data("UnfoldLinearModelContinuousTime") - uf = example_data("UnfoldLinearModel") - results = coeftable(uf) - uf_5chan = example_data("UnfoldLinearModelMultiChannel") - d_singletrial, _ = UnfoldSim.predef_eeg(; return_epoched=true) - times = -0.099609375:0.001953125:1.0 - data, positions = TopoPlots.example_data() - df = UnfoldMakie.eeg_matrix_to_dataframe(data[:,:,1], string.(1:length(positions))); - - data_erp, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) - data_erp = reshape(data_erp, (1, size(data_erp)...)) - form = @formula 0 ~ 1 + condition + continuous - se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true); - m = fit( - UnfoldModel, - Dict(Any => (form, range(0, step = 1 / 100, length = size(data_erp, 2)))), - evts, - data_erp, - solver = se_solver, - ) - results = coeftable(m) - res_effects = effects(Dict(:continuous => -5:0.5:5), m); - - plot_erp!(ga, results; :stderror=>true, legend=(; framevisible = false)) - plot_butterfly!(gb, d_topo; positions=pos, topomarkersize = 10, topoheigth = 0.4, topowidth = 0.4,) - plot_topoplot!(gc, data[:,340,1]; positions = positions) - plot_topoplotseries!(gd, df, 80; positions=positions, visual=(label_scatter=false,), - layout = (; useColorbar=true)) - 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)) - - 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, - fontsize=26, - font=:bold, - padding=(0, 5, 5, 0), - halign=:right) - end - f -end - - -@testset "8 plots with a Figure" begin - f = Figure(resolution=(1200, 1400)) - - include("../docs/example_data.jl") - d_topo, positions = example_data("TopoPlots.jl") - data, positions = TopoPlots.example_data() - uf = example_data("UnfoldLinearModel") - results = coeftable(uf) - 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], - # if coefname not specified, line should be black - coefname=["(Intercept)", "category: face"] - ) - plot_erp!(f[1, 1], results, extra=(; - categoricalColor=false, - categoricalGroup=false, - pvalue=pvals, - stderror=true)) - - plot_butterfly!(f[1, 2], d_topo; positions=positions) - plot_topoplot!(f[2, 1], data[:, 150, 1]; positions=positions) - plot_topoplotseries!(f[2, 2], d_topo, 0.1; positions=positions, visual=(label_scatter=false,), layout = (; useColorbar=true)) - plot_erpgrid!(f[3, 1], data[:, :, 1], positions) - - times = -0.099609375:0.001953125:1.0 - 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)) - - 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]]) - Label(layout[1, 1, TopLeft()], label, - fontsize=26, - font=:bold, - padding=(0, 5, 5, 0), - halign=:right) - end - f -end - - -@testset "testing combined figure (a Figure from mult_viz_in_fig from docs)" begin - include("../docs/example_data.jl") - d_topo, positions = example_data("TopoPlots.jl") - uf_deconv = example_data("UnfoldLinearModelContinuousTime") - uf = example_data("UnfoldLinearModel") - results = coeftable(uf) - uf_5chan = example_data("UnfoldLinearModelMultiChannel") - d_singletrial, _ = UnfoldSim.predef_eeg(; return_epoched=true) - data, positions = TopoPlots.example_data() - times = -0.099609375:0.001953125:1.0 - - f = Figure(resolution=(2000, 2000)) - - plot_butterfly!(f[1, 1:3], d_topo; positions=positions) - - pvals = DataFrame( - from=[0.1, 0.15], - to=[0.2, 0.5], - # 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, - pvalue=pvals, - stderror=true) - - plot_designmatrix!(f[2, 3], designmatrix(uf)) - - plot_topoplot!(f[3, 1], data[:, 150, 1]; positions=positions) - plot_topoplotseries!(f[4, 1:3], d_topo, 0.1; positions=positions, mapping=(; label=:channel)) - - 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)) - - plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legendPosition=: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)), :]; - positions=positions, predictor=:time, predictor_bounds=[-0.3, 0.5]) - - f - #save("test.png", f) -end \ No newline at end of file diff --git a/test/test_complexplots.jl b/test/test_complexplots.jl index d87c87623..9a3e9451a 100644 --- a/test/test_complexplots.jl +++ b/test/test_complexplots.jl @@ -39,7 +39,7 @@ plot_butterfly!(gb, d_topo; positions=pos, topomarkersize = 10, topoheigth = 0.4, topowidth = 0.4,) plot_topoplot!(gc, data[:,340,1]; positions = positions) plot_topoplotseries!(gd, df, 80; positions=positions, visual=(label_scatter=false,), - layout = (; useColorbar=true)) + layout = (; use_colorbar=true)) plot_erpgrid!(ge, data[:, :, 1], positions) plot_erpimage!(gf, times, d_singletrial) plot_parallelcoordinates!(gh, uf_5chan, [1, 2, 3, 4, 5]; @@ -82,7 +82,7 @@ end plot_butterfly!(f[1, 2], d_topo; positions=positions) plot_topoplot!(f[2, 1], data[:, 150, 1]; positions=positions) - plot_topoplotseries!(f[2, 2], d_topo, 0.1; positions=positions, visual=(label_scatter=false,), layout = (; useColorbar=true)) + plot_topoplotseries!(f[2, 2], d_topo, 0.1; positions=positions, visual=(label_scatter=false,), layout = (; use_colorbar=true)) plot_erpgrid!(f[3, 1], data[:, :, 1], positions) times = -0.099609375:0.001953125:1.0 diff --git a/test/test_toposeries.jl b/test/test_toposeries.jl index 161ebd305..df7401bc8 100644 --- a/test/test_toposeries.jl +++ b/test/test_toposeries.jl @@ -13,7 +13,7 @@ end df, Δbin; positions = positions, - layout = (; useColorbar = false), + layout = (; use_colorbar = false), ) end @@ -30,7 +30,7 @@ end df, Δbin; positions = positions, - layout = (; useColorbar = true), + layout = (; use_colorbar = true), ) hidespines!(ax) hidedecorations!(ax, label = false)