- one line for each column of y (or one line if y is a row vector)
- one patch object for the shading
- two edge lines
Legend doesn't show correct colors
1 次查看(过去 30 天)
显示 更早的评论
hi, i'm trying to plot my erp and the legend doesn't show the correct colors.
the code:
figure;
for i_chan = 4 %here specify the index of the channel
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_EC(i_chan,:), (SD_EC(i_chan,:)/sqrt(nsamples)), 'g',1);
hold on
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_EO(i_chan,:), (SD_EO(i_chan,:)/sqrt(nsamples)), 'b',1);
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_nonREM(i_chan,:), (SD_nonREM(i_chan,:)/sqrt(nsamples)), 'm',1);
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_REM(i_chan,:), (SD_REM(i_chan,:)/sqrt(nsamples)), 'r',1);
legend({'EC', 'EO', 'nonREM', 'REM'}, 'Location', 'southwest')
xlabel('Time [ms]')
ylabel('Amp [muV]');
xlim([-100 650]) %adjust limit based on your epoch length
title(EEG_EC_epochrej.chanlocs(chan(i_chan)).labels)
end
Thanks for the help
0 个评论
采纳的回答
Walter Roberson
2021-4-19
Your code assumes that shadedErrorBar creates exactly one graphics object per call. However if you are using https://www.mathworks.com/matlabcentral/fileexchange/26311-raacampbell-shadederrorbar then shadedErrorBar creates:
For a total of 4 graphics objects for your case (where you are passing in one row per call)
shadedErrorBar returns a struct with three fields. If you want the lines to be marked in the legend, then extract the field named mainline from the return from each of the calls. If you want the shading to be marked in the legend, then extract the field named patch from the return from each of the calls. Then pass the vector of graphic handles as the first paramter to legend(), before the legend strings.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!