필터 지우기
필터 지우기

horizontal bar graphs/ figures

조회 수: 1 (최근 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 CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by