Read and visualize projections (SSP and other)

This example shows how to read and visualize Signal Subspace Projectors (SSP) vector. Such projections are sometimes referred to as PCA projections.

# Author: Joan Massich <>
# License: BSD (3-clause)

import matplotlib.pyplot as plt

import mne
from mne import read_proj
from import read_raw_fif

from mne.datasets import sample


data_path = sample.data_path()

subjects_dir = data_path + '/subjects'
fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
ecg_fname = data_path + '/MEG/sample/sample_audvis_ecg-proj.fif'

Load the FIF file and display the projections present in the file. Here the projections are added to the file during the acquisition and are obtained from empty room recordings.

raw = read_raw_fif(fname)
empty_room_proj =['projs']

# Display the projections stored in `info['projs']` from the raw object
PCA-v1, PCA-v2, PCA-v3


Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
    Read a total of 3 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
    Range : 25800 ... 192599 =     42.956 ...   320.670 secs

Display the projections one by one

n_cols = len(empty_room_proj)
fig, axes = plt.subplots(1, n_cols, figsize=(2 * n_cols, 2))
for proj, ax in zip(empty_room_proj, axes):
PCA-v1, PCA-v2, PCA-v3

Use the function in mne.viz to display a list of projections

PCA-v1, PCA-v2, PCA-v3

The ECG projections can be loaded from a file and added to the raw object

# read the projections
ecg_projs = read_proj(ecg_fname)

# add them to raw and plot everything
PCA-v1, PCA-v2, PCA-v3, ECG-planar-999--0.200- 0.400-PCA-01, ECG-planar-999--0.200- 0.400-PCA-02, ECG-axial-999--0.200-0 .400-PCA-01, ECG-axial-999--0.200-0 .400-PCA-02, ECG-eeg-999--0.200-0.4 00-PCA-01, ECG-eeg-999--0.200-0.4 00-PCA-02


    Read a total of 6 projection items:
        ECG-planar-999--0.200-0.400-PCA-01 (1 x 203)  idle
        ECG-planar-999--0.200-0.400-PCA-02 (1 x 203)  idle
        ECG-axial-999--0.200-0.400-PCA-01 (1 x 102)  idle
        ECG-axial-999--0.200-0.400-PCA-02 (1 x 102)  idle
        ECG-eeg-999--0.200-0.400-PCA-01 (1 x 59)  idle
        ECG-eeg-999--0.200-0.400-PCA-02 (1 x 59)  idle
6 projection items deactivated

Total running time of the script: ( 0 minutes 3.741 seconds)

Estimated memory usage: 9 MB

Gallery generated by Sphinx-Gallery