Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bar plot with standard deviation

I am plotting bar plot with standard deviation in Matlab data are following

y = [0.776 0.707 1.269; 0.749 0.755 1.168; 0.813 0.734 1.270; 0.845 0.844 1.286];
std_dev = [0.01 0.055 0.052;0.067 0.119 0.106;0.036 0.077 0.060; 0.029 0.055 0.051];

I am writing following code

figure
hold on
bar(y)
errorbar(y,std_dev,'.')

But I am not getting standard deviation bar in the correct position.

like image 555
pravin kumar Avatar asked Apr 11 '26 21:04

pravin kumar


1 Answers

If all the bars have the same color:

x=1:15;
y = [0.776 0.707 1.269 0 0.749 0.755 1.168 0 0.813 0.734 1.270 0 0.845 0.844 1.286];
std_dev = [0.01 0.055 0.052 0 0.067 0.119 0.106 0 0.036 0.077 0.060 0 0.029 0.055 0.051];

figure
hold on
bar(x,y)
errorbar(y,std_dev ,'.')

XTickLabel={'1' ; '2'; '3' ; '4'};
XTick=2:4:15
set(gca, 'XTick',XTick);
set(gca, 'XTickLabel', XTickLabel);

enter image description here

like image 151
hello123 Avatar answered Apr 14 '26 10:04

hello123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!