Visualization

Visualization#

brainmass.viz provides thin plotting helpers that keep the tutorials and the gallery concise and visually consistent. Each helper surfaces a standard matplotlib plot or a braintools.metric output (functional connectivity, power spectrum) – none reimplements a metric.

Note

matplotlib is an optional dependency, imported lazily inside each function. import brainmass never imports matplotlib on behalf of viz; calling a helper without matplotlib installed raises a clear ImportError pointing at the extra. Install it with:

pip install brainmass[viz]

Every helper accepts an optional ax= (returning the matplotlib.axes.Axes it drew on) and tolerates unit-aware (brainunit.Quantity) inputs.

Plotting helpers#

plot_timeseries(signal[, ts, labels, ax])

Plot one or more region time series.

plot_phase_portrait(x, y, *[, ax])

Plot a phase portrait of one variable against another.

plot_connectivity(matrix, *[, labels, ax, ...])

Plot a connectivity (or any square) matrix as a heatmap.

plot_functional_connectivity(data, *[, ...])

Plot a functional-connectivity matrix.

plot_power_spectrum(signal, dt, *[, ax, loglog])

Plot the power spectral density of a 1-D signal.

Examples#

The doctest setup selects the Agg (headless) backend, so these run in CI:

>>> import brainmass
>>> conn = brainmass.datasets.load_dataset('example_connectome')
>>> ax = brainmass.viz.plot_connectivity(conn.weights, labels=conn.labels)
>>> len(ax.images)
1
>>> sig = brainmass.datasets.load_dataset('example_signal')
>>> ax = brainmass.viz.plot_functional_connectivity(sig.signal)
>>> len(ax.images)
1
>>> ax = brainmass.viz.plot_power_spectrum(sig.signal[:, 0], dt=sig.dt)
>>> ax.get_xlabel()
'frequency'

See Also#