The EEGLAB News #9

How do you plot standard error shades on ERP?

Question: EEGLAB user
Answers: Cédric Cannard, Ph.D, Arnaud Delorme, Ph.D., and Cyril Pernet, Ph.D.

I’ve seen this posted a few times. Seems like it’s relatively standard now to include standard error “shades” in publications these days of ERP data. I’d like to do this on my grand averaged STUDY data but am having a few hard time figuring out how to do so in EEGLAB. Does anyone have tips/tricks for doing this in EEGLAB or other (preferably simple) methods?

(EEGLAB user)


Below is an example of plotting one subject's epoched data. You should adapt the script to use the output of the STUDY function as input data for plotting.

data1 = squeeze(,:,:));
nEpochs = size(data1,2);
data1_mean = mean(data1,2)';
data1_se = std(data1 ./ sqrt(nEpochs),[],2)';
color1 = [0, 0.4470, 0.7410];
xAxis = 1:size(data1,1); %ADJUST WITH YOUR LAGS

plot(xAxis, data1_mean,'LineWidth',2,'Color',color1); hold on
fillhandle = fill([xAxis fliplr(xAxis)], [data1_mean-data1_se fliplr(data1_mean+data1_se)], color1);
set(fillhandle,'EdgeColor', color1,'FaceAlpha',0.2,'EdgeAlpha',0.8);
grid on; axis tight; box on;
ylabel('ERP amplitude','FontSize',12);
hPlots = flip(findall(gcf,'Type','Line'));
legend(hPlots, 'data1Name (SE)');

You may duplicate the lines containing data1 with data2 to superimpose another condition/group (i.e., data2).

Cedric Cannard


You can also do that at the study level

In scripts, the EEGLAB function “fillcurves" is also easy to use to create shaded areas.
See the function help message for more details.

figure; fillcurves(rand(1,100), rand(1,100)+1.5);

Arnaud Delorme


Testing differences is well performed using a hierarchical linear model
accounting for within-subject (between trials), and between subjects
variances - a robust difference (yuen t-test) can be computed
companioned by ERP Highest-density Intervals; see e.g.

Cyril Pernet