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!

采纳的回答

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