0

i want to plot different errorbars std_a/b/c in my bar graph

a=5;  std_a=0.9;  
b=6;  std_b=0.5;
c=7;  std_c=0.2;

%plot
bar([a,b,c]);
errorbar([a,b,c],[std_a,std_b,std_c]);

somehow this is not working. how can get for each bar the correct errorbar?

2 Answers 2

2

You're close. errorbar by default plots a line and adds errorbars to it, and if you haven't called hold on or hold all it will overwrite what you already have. If you just want the error bars and not lines between them, give it a plot format that only plots points, like r.:

bar([a,b,c]);
hold on
errorbar([a,b,c],[std_a,std_b,std_c],'r.');
Sign up to request clarification or add additional context in comments.

Comments

1

I had to improve location of the error bars on x axis because for more than one data series the bars appear side by side, while the error bars may appear one on top of the other.

for data with two columns and serr (standard error in my case) of the same size I used a shift to the left and right of +-1.4 (see gap in the code below).

gap=0.14;
X=1:length(data);
X=[X'-gap,X'+gap];
errorbar(X,data,serr,'k.');

you can specify a third input argument of zeros the same size of serr, if you want to minimise the bottom bars so that only top error bars show.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.