• Home
  • Blog
  • plot error bar for a horizontal bar chart (MATLAB)

plot error bar for a horizontal bar chart (MATLAB)

0 comments

Need help plot error bars for individual bars in a horizontal bar chart. My code can plot the horizontal bars but unable to get the corrected error bar. Code and final output example are attached here.

matlab code:

% bar plot question

% requirement:

% 1) horizontal bar plot for two group of data

% 2) error bar on each bar

% this is y value

data = [29.5, 8, 3.5, 9.5, 4.5, 2.2, 2.3, 4, 5.1, 40.5, 36, 16;

29.74, 8.31, 3.31, 9.10, 4.24, 1.72, 1.80, 3.3, 6.0, 49, 32, 1.2]’;

% this is the standard deviation for the error bar

std_dev = [7, 3, 1, 4, 1.9, 0.6, 0.6, 1.8, 2, 11.5, 10, 0.055;

7.45, 3.31, 1.41, 2.90, 1.4, 0.72, 0.67, 2.035, 2.96, 17.32, 9.76, 0.055]’;

% plot horizontal bar plot

h1= barh(data);

% create y axis label

yticklabels({‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’,‘I’,‘J’,‘K’,‘L’});

% add error bar on each one

hold on

er = errorbar(data,std_dev,‘horizontal’);

er.LineWidth = 1;

er.Color = ‘r’;

hold off

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}