mne.viz.plot_compare_evokeds

Hello MNE Team,

I am currently comparing evoked activity between two experimental conditions using the mne.viz.plot_compare_evokeds function. I want to change the x-axis limits to look closer on a certain time range, but the xlim label doesn’t work. Am I missing something?

Thank you for your great work,

Carina

Hello @CarinaFo and welcome to the forum!

You are right that plot_compare_evokeds() currently doesn’t support cropping the time axis to a user-specified region of interest. However, there are several ways to achieve what you want. I’ll just demonstrate here the one approach I personally find the most straightforward: we create a copy of your evokeds, crop those to the desired time range, and pass them to plot_compare_evokeds():

tmin = 0
tmax = 0.1
evokeds_to_plot = [e.copy().crop(tmin, tmax) for e in evokeds]
mne.viz.plot_compare_evokeds(evokeds_to_plot)

Here is a fully reproducible example using the MNE sample dataset:

# %%
from pathlib import Path
import mne


sample_dir = Path(mne.datasets.sample.data_path())
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

raw = mne.io.read_raw_fif(sample_fname)
raw.crop(tmax=60)

events = mne.find_events(raw, stim_channel='STI 014')
event_id = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
            'visual/right': 4, 'face': 5, 'buttonpress': 32}

epochs = mne.Epochs(raw, events=events, event_id=event_id,
                    tmin=-0.2, tmax=0.5, baseline=(None, 0),
                    preload=True)

evokeds = [
    epochs['auditory'].average(),
    epochs['visual'].average()
]

# %%
tmin = 0
tmax = 0.1
evokeds_to_plot = [e.copy().crop(tmin, tmax) for e in evokeds]
mne.viz.plot_compare_evokeds(evokeds_to_plot)

Best wishes,

Richard

1 Like

Hi @CarinaFo - I think your question is better suited for a separate thread, could you start one?

1 Like