# How to colour each individual bar with a different colour?

2 visualizzazioni (ultimi 30 giorni)
Haitham AL Satai il 11 Nov 2022
Commentato: Voss il 16 Nov 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;
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Voss il 11 Nov 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 CommentiMostra 2 commenti meno recentiNascondi 2 commenti meno recenti
Haitham AL Satai il 16 Nov 2022
@Voss I really appreciate your kindness.
Voss il 16 Nov 2022
You're welcome!

Accedi per commentare.

### Più risposte (1)

Cris LaPierre il 11 Nov 2022
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Haitham AL Satai il 11 Nov 2022
@Cris LaPierre Thank you dear.

Accedi per commentare.

### Categorie

Scopri di più su Annotations in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by