I need to hide 4 lines from the legend. I'm using shadedErrorBar so I have 3 line for a sigle group (mean, upper edge of standard deviation and bottom edge) and if i use the classic code legend('line1','line2,'...) I'll have 3 label. I want in the legend only the mean for each group.
I have 2 groups.
shadedErrorBar(x,y1,e1);
shadedErrorBar(x,y2,e2);
y1 and y2 are my means, while e1 and e2 standard deviations.
I think I should use IconDisplayStyle but I don't understand how. I read this http://it.mathworks.com/help/matlab/creating_plots/controlling-legends.html but is like hide a plot to hide a line. With shadedErrorBar I have a graph with 3 plot on it for each group.

When you create the legend, you can specify only the plot objects that you would like to create legend entries for. The output of shadedErrorBars is a struct containing all of the plot objects so you can use these to grab the patch objects and create legend entries for only those.
h1 = shadedErrorBar(linspace(1,10), linspace(1,10), linspace(0,1));
hold on
h2 = shadedErrorBar(linspace(1,10), linspace(1,20), linspace(1,0));
legend([h1.patch, h2.patch], {'Item1', 'Item2'})

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With