How to colour each individual bar with a different colour?

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(1 个)

Cris LaPierre
Cris LaPierre 2022-11-11

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by