How to draw bar graph of different colors ?
조회 수: 132 (최근 30일)
이전 댓글 표시
I have plotted the bar graph but the color is same. i want to differentiate the color of each x variable .Thank you in advance !![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/530949/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/530949/image.jpeg)
채택된 답변
Star Strider
2021년 2월 26일
Try this:
y = [280 260 240];
figure
c = bar(y);
set(gca, 'XTickLabel',{'CS0','CS10','CS20'})
xlabel('Wt% of cenospheres')
ylabel('Workability, mm')
c.FaceColor = 'flat';
c.CData(1,:) = [1 0 0];
c.CData(2,:) = [0 1 0];
c.CData(3,:) = [0 0 1];
producing:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/532749/image.png)
Experiment with different colours.
댓글 수: 7
Roger Breton
2024년 1월 18일
This works for me!
RGB = xyz2rgb(testXYZ'/100);
figure
c = bar(R);
% set(gca, 'XTickLabel',{'CS0','CS10','CS20'})
ylim([0 100])
xlabel('Element')
ylabel('Score')
title('CIE 1995 TCS Score')
c.FaceColor = 'flat';
c.CData(1,:) = RGB(1,:);
c.CData(2,:) = RGB(2,:);
c.CData(3,:) = RGB(3,:);
추가 답변 (1개)
Adam Danz
2021년 2월 26일
This has been addressed in the forum many times.
Examples:
- https://www.mathworks.com/matlabcentral/answers/553894-barcharts-colours-based-on-other-vectors#answer_456622
- https://www.mathworks.com/matlabcentral/answers/571735-custom-colors-for-stacked-bar-chart#answer_471967
- https://www.mathworks.com/matlabcentral/answers/486175-how-can-i-change-colors-and-generate-errorbars-in-a-bar-graph#answer_397071
- https://www.mathworks.com/matlabcentral/answers/506415-bar-chart-legend-and-colour
- https://www.mathworks.com/matlabcentral/answers/599512-changing-transparency-of-individual-bars-in-bar#answer_500116
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!