horizontal bar graphs/ figures

7 ビュー (過去 30 日間)
harley
harley 2013 年 10 月 1 日
編集済み: harley 2013 年 10 月 2 日
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.

採用された回答

Wayne King
Wayne King 2013 年 10 月 1 日
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]);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by