필터 지우기
필터 지우기

Stacked Bar and Legend Handles

조회 수: 1 (최근 30일)
Matlab2010
Matlab2010 2012년 6월 28일
Using 2010B.
I say:
h1=bar(x1, y1, 'r', 'stack');
hold all;
h2=bar(x2, y2, 'b', 'stack');
[legend_h, object_h, plot_h, text_strings] = legend([h1 h2],'s1','s2');
When I inspect the plot I see that the colored boxes in the legend are both red in color.
I have just spent ages trying to play with all the children etc but to no avail.
Please can someone tell me how to change the color of the rectangle inside the legend box.
thanks!

채택된 답변

Tom
Tom 2012년 6월 28일
편집: Tom 2012년 6월 28일
I'll have a stab at:
h1=bar(x1, y1, 'r', 'stack');
hg1=hggroup;
set(h1,'Parent',hg1)
hold all;
h2=bar(x2, y2, 'b', 'stack');
hg2=hggroup;
set(h2,'Parent',hg2)
set(get(get(hg1,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','on');
set(get(get(hg2,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','on');
[legend_h, object_h, plot_h, text_strings] = legend('s1','s2');
This groups each bar plot -makes it a hggroup- so that each hggroup counts as one item on the legend. The LegendInformation stuff determines whether that object appears in the legend

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by