Hello,
You can provide show=False to disable drawing in plot_compare_evokeds, then change whatever properties of the matplotlib figure you want to change and show after with plt.show. You can provide the axes on which to draw the figure with the axes argument, giving you direct access to the matplotlib axes, or retrieve the figure returned by mne.viz.plot_compare_evokeds.
With the axes argument:
import mne
from matplotlib import pyplot as plt
from mne.io import read_raw_fif
# load raw data
folder = mne.datasets.sample.data_path() / "MEG" / "sample"
raw = read_raw_fif(folder / "sample_audvis_filt-0-40_raw.fif", preload=False)
# create epochs
events = mne.find_events(raw, stim_channel='STI 014')
event_dict = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
'visual/right': 4, 'smiley': 5, 'buttonpress': 32}
epochs = mne.Epochs(raw, events, picks="eeg", event_id=event_dict, tmin=-0.2,
tmax=0.5, reject=None, preload=True)
conds_we_care_about = ['auditory/left', 'auditory/right',
'visual/left', 'visual/right']
epochs.equalize_event_counts(conds_we_care_about) # this operates in-place
aud_epochs = epochs['auditory']
vis_epochs = epochs['visual']
del raw, epochs # free up memory
# create evoked
aud_evoked = aud_epochs.average()
vis_evoked = vis_epochs.average()
# plot
fig, axes = plt.subplots(1, 1, figsize=(10, 10))
mne.viz.plot_compare_evokeds(dict(auditory=aud_evoked, visual=vis_evoked),
legend='upper left', show_sensors='upper right',
axes=axes, show=False)
axes.set_xlabel("My X label") # change properties
plt.show()
With the returned figure:
import mne
from matplotlib import pyplot as plt
from mne.io import read_raw_fif
# load raw data
folder = mne.datasets.sample.data_path() / "MEG" / "sample"
raw = read_raw_fif(folder / "sample_audvis_filt-0-40_raw.fif", preload=False)
# create epochs
events = mne.find_events(raw, stim_channel='STI 014')
event_dict = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
'visual/right': 4, 'smiley': 5, 'buttonpress': 32}
epochs = mne.Epochs(raw, events, picks="eeg", event_id=event_dict, tmin=-0.2,
tmax=0.5, reject=None, preload=True)
conds_we_care_about = ['auditory/left', 'auditory/right',
'visual/left', 'visual/right']
epochs.equalize_event_counts(conds_we_care_about) # this operates in-place
aud_epochs = epochs['auditory']
vis_epochs = epochs['visual']
del raw, epochs # free up memory
# create evoked
aud_evoked = aud_epochs.average()
vis_evoked = vis_epochs.average()
# plot
fig = mne.viz.plot_compare_evokeds(
dict(auditory=aud_evoked, visual=vis_evoked),
legend='upper left', show_sensors='upper right', show=False)
fig[0].axes[0].set_xlabel("My X label") # change properties
plt.show()
Note that depending on your data and on the channel present, the number of axes/figures differs; which is why the function mne.viz.plot_compare_evokeds returns a list of figures.