Reputation: 659
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.
Upvotes: 3
Views: 1396
Reputation: 65430
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'})
Upvotes: 2