Stacked Bar and Legend Handles
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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 Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!