How to change only 1 bar in a graphic bar that is grouped

조회 수: 1 (최근 30일)
Mar Castro Espín
Mar Castro Espín 2022년 8월 29일
댓글: Abderrahim. B 2022년 8월 29일
Y1=[CO_P2_30, NOx_P2_30, UHC_P2_30
CO_P3_10, NOx_P2_10, UHC_P3_10
CO_P3_5, NOx_P2_5, UHC_P1_5
CO_P2_3, NOx_P1_3, UHC_P1_3];
b1=bar(X,Y1,'grouped');
b1(1).FaceColor='#000000'; % CO-P1
b1(2).FaceColor='#828282'; % NOx-P1
b1(3).FaceColor='#D5D5D5'; % UHC-P1
X = categorical({'30','10','5','3'});
X = reordercats(X,{'30','10','5','3'});
I want to change the color of the first bar of the bar group of 30. When I try to change it the program change de color of the first bar of all the groups.

답변 (1개)

Abderrahim. B
Abderrahim. B 2022년 8월 29일
Hi!
Try something like this:
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
barH = bar(y) ;
barH(1).FaceColor = "flat" ;
barH(1).CData(1,:) = [0 1 0] ; % set the first bar color to green
  댓글 수: 2
Abderrahim. B
Abderrahim. B 2022년 8월 29일
My pleasure. Accept the answer if you found it helpful so others can refer to it.

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

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by