我有以下代码,但我想要的是每组的不同颜色(更多细节:在第一组中我将Stim1与Stim2,Stim3,Stim4进行比较,在第二组中我将Stim2与Stim1进行比较,Stim3,Stim4 - 同样的逻辑适用于第三组)..我该怎么做?我知道我可以用h(2).Facecolor设置特定条形的颜色,但这适用于所有组......
到目前为止我的代码:
model_series = [37 44 67; 37 39 64 ;44 39 64];
model_error = [15 7 7; 15 9 4; 7 9 3];
h = bar(model_series);
set(h,'BarWidth',1);
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
% 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
答案 0 :(得分:2)
很难将条形图设置为您想要的确切颜色,例如突出显示异常或焦点栏。 我几年前写过这篇文章,它似乎仍然有用。
https://uk.mathworks.com/matlabcentral/fileexchange/29882-coloured-bar-chart?s_tid=srchtitle