Excluding legend entries in plot

31 visualizaciones (últimos 30 días)
Jonathan
Jonathan el 16 de Oct. de 2011
Editada: Els Crijns el 22 de Mayo de 2019
Hi,
I have a figure on which I'm first plotting a shaded error bar (see shadedErrorBar in File Exchange), and then plotting several points that fall within this shaded error bar (the error bar is calculated based on the points before the fact).
Unfortunately, because of the way shadedErrorBar is written, the upper, lower, middle and shaded parts of the shaded error bar all show up when I add a legend to the figure. I've looked through Legend in help, but I'm not seeing any way to tell the legend to ignore or exclude certain entries. Is this possible? I'm sure if I had a better understanding of the syntax of plotting I'd be able to figure this out another way... but for now I'm stumped.
Thanks, Jonathan
P.S. I have considered plotting the error bar after the other points, but then I have to set the error bar's transparency, which in shadedErrorBar causes the axes and various other parts of the image also to disappear (maybe I'm doing this wrong).

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Oct. de 2011
Editada: John Kelly el 26 de Feb. de 2015
The documentation indicates,
legend(h,'string1','string2',...) displays a legend on the plot containing the objects identified by the handles in the vector h and uses the specified strings to label the corresponding graphics object (line, barseries, etc.).
Thus one way of proceeding is to collect the handles of what you do want to be legend'd and legend() that.
You can also proceed by setting the IconDisplayStyle of the Annotation property of the items you do not want to appear in the legend. See here for information and examples.
  2 comentarios
Jonathan
Jonathan el 17 de Oct. de 2011
Thanks Walter. The latter option solved my issue.
Sandesh Permude
Sandesh Permude el 14 de Mayo de 2014
simple way, its there in the function reference too, but could not understand it from there, Thanks.

Iniciar sesión para comentar.

Más respuestas (1)

Alberto Jr
Alberto Jr el 6 de Jul. de 2015
Hello I am trying to plot my data in matlab using the shadederrorbar. Can you post your code here so I can reference it? Thank you!
  1 comentario
Els Crijns
Els Crijns el 22 de Mayo de 2019
Editada: Els Crijns el 22 de Mayo de 2019
I was eventually able to solve based on the replies of a similar question: https://nl.mathworks.com/matlabcentral/answers/406-how-do-i-skip-items-in-a-legend#answer_562 :
If you have just one line on the plot :
h=shadedderrorbar(...);
legend([h.mainLine], 'Vars1')
or for multiple lines on one plot:
figure; hold on,
h(1)=shadedderrorbar(...);
h(2)=shadedderrorbar(...);
legend([h(2).mainLine h(1).mainLine], 'Vars1', 'Vars2')
The same would be possible for the borders or the fill of the shaded area , using h.edge or h.patch respectively.

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by