隐藏图例中的线

Hide line from legend

我需要隐藏图例中的 4 行。我正在使用 shadedErrorBar,所以我有 3 行用于单个组(平均值,标准偏差的上边缘和下边缘),如果我使用经典代码 legend('line1','line2,'...),我将有 3 个标签。我只想要图例中每组的平均值。 我有2组。

shadedErrorBar(x,y1,e1);
shadedErrorBar(x,y2,e2);

y1y2 是我的均值,而 e1e2 是标准差。 我想我应该使用 IconDisplayStyle,但我不明白如何使用。我读了这个 http://it.mathworks.com/help/matlab/creating_plots/controlling-legends.html 但就像隐藏一个 plot 来隐藏一行。使用 shadedErrorBar 我有一个图表,每组都有 3 个图。

创建图例时,you can specify only the plot objects that you would like to create legend entries forshadedErrorBars 的输出是一个包含所有绘图对象的结构,因此您可以使用它们来获取补丁对象并为 那些对象创建图例条目。

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'})