How to colour each individual bar with a different colour?

조회 수: 1 (최근 30일)
Haitham AL Satai
Haitham AL Satai 2022년 11월 11일
댓글: Voss 2022년 11월 16일
I would like to colour each individual bar with a different colour. Any assistance, please?
My example below:
CoverageArea = [101.1303,0,114.9316,45.2112,116.5973,95.8953];
bar(CoverageArea)
ylabel('Coverage area (m²)');
xticklabels({'\Phi_1_/_2 = 15, (\phi & \psi) =\pm 10','\Phi_1_/_2 = 15, (\phi & \psi) =\pm 40','\Phi_1_/_2 = 30, (\phi & \psi) =\pm 10','\Phi_1_/_2 = 30, (\phi & \psi) =\pm 40','\Phi_1_/_2 = 60, (\phi & \psi) =\pm 10','\Phi_1_/_2 = 60, (\phi & \psi) =\pm 40'})
grid on;

채택된 답변

Voss
Voss 2022년 11월 11일
CoverageArea = [101.1303,0,114.9316,45.2112,116.5973,95.8953];
h = bar(CoverageArea);
ylabel('Coverage area (m²)');
xticklabels({'\Phi_1_/_2 = 15, (\phi & \psi) =\pm 10','\Phi_1_/_2 = 15, (\phi & \psi) =\pm 40','\Phi_1_/_2 = 30, (\phi & \psi) =\pm 10','\Phi_1_/_2 = 30, (\phi & \psi) =\pm 40','\Phi_1_/_2 = 60, (\phi & \psi) =\pm 10','\Phi_1_/_2 = 60, (\phi & \psi) =\pm 40'})
grid on;
colors = get(gca(),'ColorOrder') % use whatever colors you want here
colors = 7×3
0 0.4470 0.7410 0.8500 0.3250 0.0980 0.9290 0.6940 0.1250 0.4940 0.1840 0.5560 0.4660 0.6740 0.1880 0.3010 0.7450 0.9330 0.6350 0.0780 0.1840
set(h,'FaceColor','flat','CData',colors(1:6,:)) % set the bars' colors
  댓글 수: 4
Haitham AL Satai
Haitham AL Satai 2022년 11월 16일
@Voss I really appreciate your kindness.
Voss
Voss 2022년 11월 16일
You're welcome!

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

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 11월 11일

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by