필터 지우기
필터 지우기

Bar plot color, why [1 0 0] does not gives red

조회 수: 5 (최근 30일)
Giuseppe Naselli
Giuseppe Naselli 2022년 7월 15일
댓글: Voss 2022년 7월 15일
Hi All and thanks for reading this.
I want to color some of the bars in this plot in red but the color I get is not as expected (as for rgb = [1 0 0] )
Am I doing something wrong? or ....
My code is below
figure('Color','w', 'Units','normalized', 'Position',[0.3906 0.6778 0.2037 0.2514])
yDataGreen = [ 5 7 9];
yDataRed = [ 6 8 10];
xData = 1:3;
barPlot1 = bar(xData, [yDataGreen; yDataRed]) ; hold on; grid minor; box on; title('That does not look the Red I want')
barPlot1(1).FaceColor = 'flat';
barPlot1(1).CData(:,:) = [0 1 0; 0 1 0; 0 1 0]; %green
barPlot1(2).CData(:,:) = [1 0 0; 1 0 0; 1 0 0]; %red

채택된 답변

Voss
Voss 2022년 7월 15일
편집: Voss 2022년 7월 15일
You have to set FaceColor to 'flat' in order for CData to take effect, which you are doing for the first bar but not for the second.
figure('Color','w', 'Units','normalized', 'Position',[0.3906 0.6778 0.2037 0.2514])
yDataGreen = [ 5 7 9];
yDataRed = [ 6 8 10];
xData = 1:3;
barPlot1 = bar(xData, [yDataGreen; yDataRed]) ; hold on; grid minor; box on; title('Now that does look like the Red you want')
barPlot1(1).FaceColor = 'flat';
barPlot1(2).FaceColor = 'flat'; % set both
% or set both at once:
% set(barPlot1,'FaceColor','flat')
barPlot1(1).CData(:,:) = [0 1 0; 0 1 0; 0 1 0]; %green
barPlot1(2).CData(:,:) = [1 0 0; 1 0 0; 1 0 0]; %red
  댓글 수: 2
Giuseppe Naselli
Giuseppe Naselli 2022년 7월 15일
Thanks!!!!!!
Voss
Voss 2022년 7월 15일
You're welcome! Any questions, let me know. Otherwise, please "Accept This Answer". Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by