Complex and Tiled Plots

Initialize NeuroAnalyzer
using NeuroAnalyzer
using CairoMakie
CairoMakie.activate!(type = "png")
# Quarto sets a default figure size (672 × 480 px), which overrides the sizes of
# NeuroAnalyzer figures: remove it
delete!(CairoMakie.Makie.CURRENT_DEFAULT_THEME, :resolution)
NeuroAnalyzer.progress_bar = false

# EEG channels only
eeg = load_neuro("files/eeg/eeg.hdf")
eeg = keep_channel(eeg; ch = "eeg")

NeuroAnalyzer plotting functions return Makie figures (GLMakie.Figure), which can be combined into one figure.

Tip: functions that open an interactive window by default (e.g. NeuroAnalyzer.plot(), plot_locs()) must be called with gui = false to return a static figure.

Composing Plots

plot_compose() arranges a vector of figures in a grid (rows, columns); empty cells are added if there are fewer figures than cells:

p1 = NeuroAnalyzer.plot(eeg; ch = "O1", seg = (5, 7), gui = false)
p2 = plot_psd(eeg; ch = "O1", seg = (5, 7))
p3 = plot_spectrogram(eeg; ch = "O1", seg = (5, 7), flim = (0, 40))
plot_compose([p1, p2, p3]; layout = (3, 1))

All figures are placed in cells of the size of the largest figure, so for best results they should have the same size.

Custom Layouts

For other layouts, a figure can be rendered to an image and placed in any cell of a Makie grid layout, e.g. a signal over the whole width and two smaller plots below it:

# draw figure f (rendered to an image) in the grid position pos
function place!(pos, f)
    ax = Axis(pos; aspect = DataAspect(), yreversed = true)
    image!(ax, permutedims(Makie.colorbuffer(f)))
    hidedecorations!(ax)
    hidespines!(ax)
    return nothing
end

p3 = plot_locs(eeg; ch = "eeg", sch = "O1", gui = false)
fig = Figure(size = (1200, 1000))
place!(fig[1, 1:2], p1)
place!(fig[2, 1], p2)
place!(fig[2, 2], p3)
fig

A figure can also be added as an inset to another figure using add_inset() (see the channel locations tutorial).

Tiled Plots

A tiled plot of the auto-covariance of several channels. First, the data:

ac = acov(eeg; ch = "eeg", l = 50)
l = labels(eeg)
size(ac.autocov)
(19, 101, 1)

Next, a vector of plots:

p = [plot_xac(ac.autocov[idx, :, 1],
              ac.lags;
              title = l[idx]) for idx in 1:8]

and the tiled plot:

plot_compose(p; layout = (4, 2))