how do i plot specific colours with a barh graph. i can plot specific colours for the first stacked bar graph but not for the second as h =barh... only produces 'h' values for the first stacked bar graph. Any help would be appreciated. Thx
MJ_Green= 50;
MJ_Yellow= 5;
MJ_Red=25;
MN_Yellow =5;
MN_Green=25;
MN_Red=50;
Red_time_both= 2;
%
Phasing_ALL = [MJ_Green, MJ_Yellow, MJ_Red, Red_time_both ; MN_Red, MN_Green, MN_Yellow, Red_time_both];
h = barh(Phasing_ALL,0.5,'stacked');
xlabel('Seconds','FontSize',12);
set(gca,'yticklabel',{'Major Road','Minor Road'});
set(h(1),'Facecolor','g');
set(h(2),'Facecolor','y');
set(h(3),'Facecolor','r');
set(h(4),'Facecolor','m');
need to set colours for second bar also.

 Réponse acceptée

Wayne King
Wayne King le 1 Oct 2013

0 votes

You have to realize that in a stacked bar plot you really have 2 bar plot objects, not 3 like you seem to think. You can modify the two 'Facecolors', the first group of bars and the second group
A = [50 25; 5 5 ; 25 50];
h = barh(A,0.75,'stacked');
xlabel('Seconds');
set(gca,'yticklabel',{'Green','Yellow','Red'});
set(h(1),'Facecolor','yellow');
set(h(2),'Facecolor','red');
Or pass a vector
A = [50 25; 5 5 ; 25 50];
h = barh(A,0.75,'stacked');
xlabel('Seconds');
set(gca,'yticklabel',{'Green','Yellow','Red'});
set(h(1),'Facecolor',[0.5 0.5 0.5]);
set(h(2),'Facecolor',[1 1 1]);

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Data Plots dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by