Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.

nilearn.plotting.plot_design_matrix

nilearn.plotting.plot_design_matrix(design_matrix, rescale=True, axes=None, output_file=None)[source]

Plot a design matrix.

Parameters:
design matrixpandas.DataFrame or str or pathlib.Path to a TSV event file

Describes a design matrix.

rescalebool, default=True

Rescale columns magnitude for visualization or not.

axesmatplotlib.axes.Axes or None, default=None

Handle to axes onto which we will draw the design matrix.

output_filestr or pathlib.Path or None, default=None

The name of an image file to export the plot to. Valid extensions are .png, .pdf, .svg. If output_file is not None, the plot is saved to a file, and the display is closed.

Returns:
axesmatplotlib.axes.Axes

The axes used for plotting.

Examples

>>> import numpy as np
>>> from pandas import DataFrame
>>> from nilearn.glm.first_level import make_first_level_design_matrix
>>> from nilearn.plotting import plot_design_matrix, show
>>>
>>> # creating a design matrix
>>> frame_times = np.arange(9)
>>> onsets = np.arange(9)
>>> duration = np.linspace(1, 9, 9)
>>> trial_type = ["ET_0", "ET_0", "ET_0",
...             "ET_1", "ET_1", "ET_1",
...             "ET_2", "ET_2", "ET_2"]
>>> events = DataFrame({"trial_type": trial_type,
...                    "onset": onsets,
...                    "duration": duration})
>>> design_matrix = make_first_level_design_matrix(frame_times, events)
>>>
>>> ax = plot_design_matrix(design_matrix)
>>>
>>> show()
../../_images/nilearn-plotting-plot_design_matrix-1.png

Examples using nilearn.plotting.plot_design_matrix

Intro to GLM Analysis: a single-run, single-subject fMRI dataset

Intro to GLM Analysis: a single-run, single-subject fMRI dataset

Analysis of an fMRI dataset with a Finite Impule Response (FIR) model

Analysis of an fMRI dataset with a Finite Impule Response (FIR) model

Examples of design matrices

Examples of design matrices

Understanding parameters of the first-level model

Understanding parameters of the first-level model

Example of second level design matrix

Example of second level design matrix

Second-level fMRI model: two-sample test, unpaired and paired

Second-level fMRI model: two-sample test, unpaired and paired

Voxel-Based Morphometry on OASIS dataset

Voxel-Based Morphometry on OASIS dataset

Beta-Series Modeling for Task-Based Functional Connectivity and Decoding

Beta-Series Modeling for Task-Based Functional Connectivity and Decoding