Different colors for plotting bar plots
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I plot three group of bars with errorbars as follows - but the problem is that I want to set for each group the colors differently (I try to do that with the switch statement, but it does not work):
model_series = [10 40 80; 20 50 90; 30 60 70];
model_error = [1 4 8; 2 5 9; 3 6 10];
h = bar(model_series);
set(h,'BarWidth',1); % The bars will now touch each other
set(gca,'YGrid','on')
set(gca,'GridLineStyle','-')
set(gca,'xtick',[1 2 3 ])
set(gca,'xticklabel',{'Stimulation 1', 'Stimulation 2', 'Stimulation 3'})
set(get(gca,'YLabel'),'String','Classification Accuracy')
hold on;
numgroups = size(model_series, 1);
numbars = size(model_series, 2);
groupwidth = min(0.8, numbars/(numbars+1.5));
for i = 1:numbars
j=i;
switch j
case 1
lh = legend('Stim2','Stim3','Stim4');
set(lh,'Location','BestOutside','Orientation','horizontal')
case 2
lh = legend('Stim1','Stim3','Stim4');
set(lh,'Location','BestOutside','Orientation','horizontal')
case 3
lh = legend('Stim1','Stim2','Stim3');
set(lh,'Location','BestOutside','Orientation','horizontal')
end
% Based on barweb.m by Bolu Ajiboye from MATLAB File Exchange
x = (1:numgroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*numbars); % Aligning error bar with individual bar
errorbar(x, model_series(:,i), model_error(:,i), 'k', 'linestyle', 'none');
end
The thing is that in the first group, I plot the comparison of Stim1 with Stim2, Stim3 and Stim4, while in the second group I plot the comparison of Stim2 with Stim1, Stim3 and Stim4 and so forth...how could I display the colors accordingly?
Thanks
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!