Matlab 更改组条形图中的颜色

Matlab 更改组条形图中的颜色,matlab,plot,colors,bar-chart,matlab-figure,Matlab,Plot,Colors,Bar Chart,Matlab Figure,我正在用错误条绘制分组条。现在,这些条不是黄色就是蓝色。我想改变这一点:每组中的条形图应该仍然有不同的颜色,但我想选择黄色和蓝色以外的颜色。这怎么可能呢 model_series = [0.74*100, 0.5*100; 0.74*100, 0.5*100;0.74*100, 0.5*100 ]; model_error = [4.8,5.9;0, 0; 0,6]; %subplot(2,1,1) h = bar(model_series); set(h,'BarWidth',1);

我正在用错误条绘制分组条。现在,这些条不是黄色就是蓝色。我想改变这一点:每组中的条形图应该仍然有不同的颜色,但我想选择黄色和蓝色以外的颜色。这怎么可能呢

model_series = [0.74*100, 0.5*100; 0.74*100, 0.5*100;0.74*100, 0.5*100 ];
model_error = [4.8,5.9;0, 0; 0,6];

%subplot(2,1,1)

h = bar(model_series);
set(h,'BarWidth',1);    % The bars will now touch each other
set(gca,'YGrid','on')
set(gca,'GridLineStyle','-')
%set(h,'FaceColor',[0.2,0.5,0.3])
set(gca,'YLim',[0 100])
title(['\fontsize{16}Accuracies'])

set(gca,'xtick',[1 2 3 4 5 6])
set(gca,'xticklabel',{'\fontsize{16}1.condition','\fontsize{16}2.condition','\fontsize{16}3.condition'})
set(get(gca,'YLabel'),'String','\fontsize{16}Accuracy')

hold on;
numgroups = size(model_series, 1); 
numbars = size(model_series, 2); 
groupwidth = min(0.8, numbars/(numbars+1.5));
legend('\fontsize{16}Group1','\fontsize{16}Group2','\fontsize{16}Group3')

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

您想要更改的属性确实是在代码中注释掉的属性。你像
set(h,'FaceColor',[0.2,0.5,0.3])
那样编写它,它改变了所有条的
'FaceColor'
。如果每个条需要不同的颜色,则需要为每个条指定不同的颜色,如下所示:

set(h(1), 'FaceColor', 'm');  %Changing color of first bar to magenta
set(h(2), 'FaceColor', 'g');  %Changing color of second bar to green

对于MATLAB R2014b及更高版本,还可以使用访问/更改属性

h(1).FaceColor = 'm';         %Changing color of first bar to magenta
h(2).FaceColor = 'g';         %Changing color of second bar to green