![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290092/image.png)
how to change the colours of a bar chart
조회 수: 1 (최근 30일)
이전 댓글 표시
The MATLAB script below produces the following bar chart. How do I change the colour of one dataset to white and one to grey.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290085/image.jpeg)
I have tried this but it does not seem to work
set(ctr,'FaceColour','grey')
set(ydt,'FaceColour','white')
MATLAB Script
x=categorical({'Q3','Q6','Q10','Q15','Q30','Q50'});
z=[2.891586318,1.99422657,1.907652812,4.71298388,6.007681496,6.718181667;3.229392123,3.36482536,4.089746011,5.204662107,6.761377397,7.978099976];
y=transpose(z);
a=[0.167797,0.314574,0.081018,0,0.116596,0;0,0.173132,0,0.231752,1.15677,1.204734];
errorplus=a;
errorminus=errorplus;
figure;
bar(x,y);
hBar = bar(y, 0.8);
for k1 = 1:size(y,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, hBar(k1).XOffset');
ydt(k1,:) = hBar(k1).YData;
end
hold on
errorbar(ctr, ydt, errorplus, '.k')
hold off
ylabel('Signal Intensity','FontSize',18)
set(gca,'linewidth',2,'FontSize',14)
ylim([0 10]);
set(gca,'XTickLabel',cellstr(x))
댓글 수: 0
채택된 답변
Mehmed Saad
2020년 5월 4일
편집: Mehmed Saad
2020년 5월 4일
hBar(1).FaceColor = 'flat';hBar(2).FaceColor = 'flat';
hBar(1).CData =rand(size(hBar(1).CData,1),3);
hBar(2).CData =rand(size(hBar(2).CData,1),3);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/290092/image.png)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!