- 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
조회 수: 9 (최근 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!