How to change the color of the bars in a bar chart?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
the cyclist
le 13 Nov 2014
Commenté : Star Strider
le 14 Nov 2014
Make a simple bar chart (and get its handle):
figure hb = bar(magic(3));
How can I set the colors of those bars now (after I have made the figure)? I know that I could have inserted another argument into the bar function, but suppose I didn't.
I am specifically asking about MATLAB 2014b.
0 commentaires
Réponse acceptée
Star Strider
le 13 Nov 2014
Here’s one way:
d = magic(3);
figure(1)
hb = bar(d)
hb(1).FaceColor = 'r';
hb(2).FaceColor = 'm';
hb(3).FaceColor = 'c';
2 commentaires
Star Strider
le 14 Nov 2014
My pleasure!
HG2 is proving to be anything but obvious. I just learned a few days ago that it’s possible to get the actual bar position information from 'XData', and to change the tick values on what was previously the x-axis, it’s necessary to set 'YTickLabel' values.
I’m sure other mysteries are yet to be discovered.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line 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!