Changing bar graph bar colors
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hail
am 24 Jul. 2014
Bearbeitet: Kelly Kearney
am 24 Jul. 2014
I have a bar graph that creates 4 different bars. I want the first bar to be colored black, the second blue, the third green, and the fourth red. How do I achieve this?
Thanks
0 Kommentare
Akzeptierte Antwort
Kelly Kearney
am 24 Jul. 2014
Bearbeitet: Kelly Kearney
am 24 Jul. 2014
By default, all the bars in a bar graph are part of the same patch object, and therefore are the same color. To get different colors, you need to plot each bar as its own object.
x = 1:4;
y = rand(1,4);
h = bar(x, diag(y), length(y));
set(h, {'facecolor'}, {'k','b','g','r'}');
or
h = bar(x, diag(y), 'stacked');
set(h, {'facecolor'}, {'k','b','g','r'}');
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!