Drawing Error bars with specific linestyle

15 views (last 30 days)
Hello to everybody, does anyone know a way for drawing errorbars with the same style of the data line?
For example, when using:
d = errorbar(x,y,y_error,'Linestyle', ':');
MATLAB returns the data lines in dotted style, while the bars in each of the points are straight. What if I want also the bars in the dotted style?

Accepted Answer

Savio Sciancalepore
Savio Sciancalepore on 2 Aug 2016
EDIT, issued solved.
There is an undocumented "Bar" property associated with the errorbar command.
Therefore, you can set the style of your bar line with a syntax like this:
d = errorbar(1:3, 1:3, 1:3, 'LineStyle', ':');
d.Bar.LineStyle = 'dotted';

More Answers (1)

dpb
dpb on 2 Aug 2016
Set the 'linestyle' property of the second errorbar series object obtained from the hggroup handle returned by errorbar -- from the example
>> X = 0:pi/10:pi;
Y = sin(X);
E = std(Y)*ones(size(X)); % the example data...
>> hE=errorbar(X,Y,E); % save handle this time
>> get(hE,'type') % what is the handle?
ans =
hggroup
>> hEC=get(hE,'children'); % and get the objects
>> get(hEC,'type') % and what are they???
ans =
'line'
'line'
>>
Aha! they're the two lines...take a chance the errorbars are the second; data the first...
>> set(hEC(2),'linestyle',':')
>>
Unfortunately, TMW didn't implement being able to set both 'linestyle' properties from the UI named parameter. If they'd accept a cell array of strings, could apply them to the two objects if present but didn't so you have to set the property separately after locating the proper object handle.

Community Treasure Hunt

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

Start Hunting!