Legend with Error Bars

34 views (last 30 days)
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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Feb 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

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!