Legend with Error Bars

31 visualizaciones (últimos 30 días)
MathWorks Support Team
MathWorks Support Team el 21 de Feb. de 2019
Respondida: MathWorks Support Team el 26 de Mzo. de 2019
I have a plot that includes several lines with error bars and a legend. I want the legend to only show the different lines, but when I create the legend it also includes a label for the error bars. How do I remove the error bars from the legend?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 21 de Feb. de 2019
If you add the "errorbar" after _y_ou add the “legend”, the “legend” will automatically update to include the new “errorbar” handle. There are two ways around this.
You can add the “errorbar” before you add the “legend”:
% code for Line_1 and Line_2
errorbar(x, y, y_lower, y_upper, '.')
legend({'Line_1','Line_2'}) % The legend will only annotate the two labels you provided
Alternatively, if you need to add the “errorbar” after you add the “legend”, you can set the “errorbar” handle to be invisible. This will prevent the “legend” from updating with the new “errorbar” handle:
% code for Line_1 and Line_2
legend({'Line_1','Line_2'})
errorbar(x, y, y_lower, y_upper, '.', 'HandleVisibility','off') % The errorbar handle is not visible, preventing the legend from updating

Más respuestas (0)

Categorías

Más información sobre Errorbars en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by