- 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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mandana Fröhlich
le 19 Avr 2021
Commenté : Mandana Fröhlich
le 19 Avr 2021
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 commentaires
Réponse acceptée
Walter Roberson
le 19 Avr 2021
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!