Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

plotting

plotting

DesignMatrix visualization functions.

Standalone functions extracted from DesignMatrix methods. Each takes a DesignMatrix instance (dm) as its first argument. DesignMatrix.plot dispatches over method to the helpers here, mirroring BrainData.plot.

Attributes:

NameTypeDescription
VALID_PLOT_METHODS

Methods:

NameDescription
plot_corrRender a labeled correlation heatmap of the columns.
plot_designmatrixVisualize a DesignMatrix, dispatching over method.
plot_matrixRender the design matrix as an SPM-style heatmap (rows=TRs, cols=regressors).
plot_timeseriesPlot regressor time courses as overlaid lines.

Classes

Methods

plot_corr

plot_corr(dm: DesignMatrix, *, columns: list[str] | None = None, metric: str = 'pearson', figsize: tuple | None = None, title: str | None = None, cmap: str | None = None, ax: plt.Axes | None = None, save: str | None = None, **kwargs: str | None)

Render a labeled correlation heatmap of the columns.

Reuses DesignMatrix.corr, which returns a similarity Adjacency with the unit diagonal dropped; the diagonal is restored to 1.0 here so the heatmap reads as a standard correlation matrix.

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixDesignMatrix instance.required
columnslist [ str ] | NoneSubset of columns to correlate. Defaults to all columns.None
metricstr'pearson' (default) or 'spearman'.‘pearson’
figsizetuple | NoneFigure size; scales with the number of columns when omitted.None
titlestr | NoneOptional axis title.None
cmapstr | NoneColormap name. Default: 'RdBu_r'.None
axAxes | NoneExisting axis to draw on; a new figure is created if omitted.None
savestr | NoneOptional path to save the figure.None
**kwargsForwarded to seaborn.heatmap (e.g. annot=False).{}

Returns:

TypeDescription
matplotlib.figure.Figure

plot_designmatrix

plot_designmatrix(dm: DesignMatrix, method: str = 'matrix', *, columns: list[str] | None = None, rescale: bool = True, metric: str = 'pearson', ax: plt.Axes | None = None, figsize: tuple | None = None, title: str | None = None, cmap: str | None = None, save: str | None = None, **kwargs: str | None)

Visualize a DesignMatrix, dispatching over method.

See DesignMatrix.plot for the full argument documentation.

Returns:

TypeDescription
matplotlib.figure.Figure: The figure containing the plot.

plot_matrix

plot_matrix(dm: DesignMatrix, *, columns: list[str] | None = None, rescale: bool = True, figsize: tuple | None = None, title: str | None = None, cmap: str | None = None, ax: plt.Axes | None = None, save: str | None = None, **kwargs: str | None)

Render the design matrix as an SPM-style heatmap (rows=TRs, cols=regressors).

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixDesignMatrix instance.required
columnslist [ str ] | NoneSubset of columns to plot. Defaults to all columns.None
rescaleboolIf True, rescale each column by its L2 norm so columns with different native magnitudes are visually comparable (SPM/nilearn convention). Default: True.True
figsizetuple | NoneFigure size; defaults to (4, 6) when a new figure is made.None
titlestr | NoneOptional axis title.None
cmapstr | NoneColormap name. Default: 'gray'.None
axAxes | NoneExisting axis to draw on; a new figure is created if omitted.None
savestr | NoneOptional path to save the figure.None
**kwargsForwarded to seaborn.heatmap.{}

Returns:

TypeDescription
matplotlib.figure.Figure

plot_timeseries

plot_timeseries(dm: DesignMatrix, *, columns: list[str] | None = None, figsize: tuple | None = None, title: str | None = None, ax: plt.Axes | None = None, save: str | None = None, **kwargs: str | None)

Plot regressor time courses as overlaid lines.

One line is drawn per column. Pass the same ax across calls to overlay multiple DesignMatrices (e.g. original vs. convolved).

Parameters:

NameTypeDescriptionDefault
dmDesignMatrixDesignMatrix instance.required
columnslist [ str ] | NoneSubset of columns to plot. Defaults to all columns.None
figsizetuple | NoneFigure size; defaults to (8, 4) when a new figure is made.None
titlestr | NoneOptional axis title.None
axAxes | NoneExisting axis to draw on; a new figure is created if omitted.None
savestr | NoneOptional path to save the figure.None
**kwargsForwarded to matplotlib.axes.Axes.plot for each line.{}

Returns:

TypeDescription
matplotlib.figure.Figure