Stacked Bar and Legend Handles
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Tom
il 28 Giu 2012
Modificato: Tom
il 28 Giu 2012
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!