How can I change the colour of specific bars in a bar graph
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alex Samson
le 17 Déc 2020
Commenté : Alex Samson
le 18 Déc 2020
Hi,
I want to change the colour of the bars in a bar graph according to a category that each of the variables fall into.
For example, there are 25 variables (25 bars on my bar graph). Bars 1 -7 are a category, 8 - 10, 11- 9 a, 20-22, and 23-25.
Here are the values for the y-axis:
0.3593, -1.2546, 0.9986, 4.1348, -2.3126, -0.2999, -2.8599; (genetics category)
6.7126, -1.9890, -1.9099; (biomarkers category)
8.8851, 8.5652, 6.2261, 4.5569, 7.0883, 9.5378, 7.5932, 14.9368, 15.7487; (cognitive category)
-9.7093, -6.9533, -5.8677; (psychological category)
-1.6640, -1.1083, -0.9188; (vascular cateogory)
*Attached is what the current graph looks like in one colour
0 commentaires
Réponse acceptée
Doddy Kastanya
le 17 Déc 2020
You can create a handle on the graph and replace the properties accordingly. Here is an example.
>> x=[1:10];
>> b=bar(x);
>> b.FaceColor='flat';
>> b.CData(2,:)=[0.5 0 0.5];
>> b.CData(6,:)=[0.3 0.2 0.5];
>> b.CData(10,:)=[0.1 0.7 0.2];
The last three lines changes the color of the second, sixth, and last bar.
I hope this helps.
3 commentaires
Doddy Kastanya
le 17 Déc 2020
You can simply use a for-loop for this. For example:
>> for i=1:4,
b.CData(i,:)=[0.5 0 0.5];
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Bar Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!