How to colour each individual bar with a different colour?

1 visualización (últimos 30 días)
Haitham AL Satai
Haitham AL Satai el 11 de Nov. de 2022
Comentada: Voss el 16 de Nov. de 2022
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;

Respuesta aceptada

Voss
Voss el 11 de Nov. de 2022
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 comentarios
Haitham AL Satai
Haitham AL Satai el 16 de Nov. de 2022
@Voss I really appreciate your kindness.
Voss
Voss el 16 de Nov. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

Cris LaPierre
Cris LaPierre el 11 de Nov. de 2022

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by