Different colors for plotting bar plots
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!