2017-10-21 1 views
2

그룹화 된 막대를 오류 막대와 함께 플롯하고 있습니다. 지금은 막대가 노란색 또는 파란색입니다. 나는 그것을 바꿔보고 싶다 : 각 그룹 내의 막대는 여전히 다른 색깔을 가져야하지만, 나는 노란색과 파란색보다 다른 것을 선택하고 싶다. 어떻게이 일을 할 수 있겠습니까?그룹 막대 그래프의 색상 변경

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 

답변

1

변경하려는 속성은 실제로 코드에서 주석 처리 된 'FaceColor'입니다. 당신은 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 이상 버전으로

, 당신은 또한 액세스에 dot notation을 사용할 수 있습니다 /를 변경 속성.

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

output

관련 문제