mne_denoise.viz.plot_spectrogram_comparison#

mne_denoise.viz.plot_spectrogram_comparison(inst_before, inst_after, picks, times, sfreq=None, fmin=1, fmax=40, n_freqs=20, show=True, fname=None)[source]#

Compare before/after spectrograms averaged across selected channels.

Parameters:
  • inst_before (MNE object | ndarray) – Inputs to compare. Either both MNE objects or both arrays. Array inputs must be 2D (n_channels, n_times) or 3D (n_epochs, n_channels, n_times).

  • inst_after (MNE object | ndarray) – Inputs to compare. Either both MNE objects or both arrays. Array inputs must be 2D (n_channels, n_times) or 3D (n_epochs, n_channels, n_times).

  • picks (sequence of int) – Explicit channel picks used for averaging.

  • times (array-like of shape (n_times,)) – Explicit time vector used on x-axis.

  • sfreq (float | None) – Sampling frequency for array inputs.

  • fmin (float) – Frequency bounds for the spectrogram.

  • fmax (float) – Frequency bounds for the spectrogram.

  • n_freqs (int) – Number of frequencies in the display grid.

  • show (bool) – If True, display the figure.

  • fname (path-like | None) – Optional output path used to save the figure.

Returns:

fig – Figure handle.

Return type:

matplotlib.figure.Figure

Raises:

ValueError – If picks/times are invalid, if input types are mixed, if array inputs are missing sfreq, or if shape constraints fail.

Notes

This function enforces an explicit times input for both MNE and NumPy inputs to avoid hidden axis inference.

Examples

>>> import numpy as np
>>> from mne_denoise.viz import plot_spectrogram_comparison
>>> before = np.random.randn(8, 2000)
>>> after = before * 0.8
>>> t = np.arange(before.shape[-1]) / 250.0
>>> fig = plot_spectrogram_comparison(
...     before, after, picks=[0, 1], times=t, sfreq=250.0, show=False
... )