フィルターのクリア

Grouped horizontal bar chart with error bars

2 ビュー (過去 30 日間)
Sarah Garre
Sarah Garre 2014 年 4 月 1 日
回答済み: jitendra 2020 年 2 月 3 日
I am trying to make a horizontal bar chart with of measurements of 3 treatments at 6 different depths. This means I have a group of tree bars for each of the 6 depths (y-axis). I would like to add to each of the bars an (so 3x6 values) the error bar based on the standard deviation.
I tried with the function herrorbar.m (file exchange), which gives me the error bars indeed for all 6 depths and each of the 3 treatments, but at 1 depth, the errorbars are all displayed at exactly the same spot on the y-axis, whereas the bars are situated on top of each other. This means that the errorbars all fall on the middle bar of the three. (see picture in attachment)
Any ideas?
Best regards

回答 (1 件)

jitendra
jitendra 2020 年 2 月 3 日
% Horizontal bar plot with error.
% data
% Data to be plotted as a bar graph
model_series = [10 40 ; 20 50 ; 30 60; 10 10 ];
%Data to be plotted as the error bars
model_error = [1 4 ; 2 5 ; 3 6; 1 2 ];
%model_series = [maleMean' femaleMean'];
%model_error = [maleVar' femaleVar'];
% Creating axes and the bar graph
h = barh(model_series,'BarWidth',1);
% Set color for each bar face
% h(1).FaceColor = 'blue';
% h(2).FaceColor = 'yellow';
% Properties of the bar graph as required
% Naming each of the bar groups
%yticklabels({ 'ORIGINAL', 'AP=0', 'WORLD','PROPOSED'})
yticklabels({ 'METHOD1', 'METHOD2', 'METHOD3','METHOD4'})
% X and Y labels
%xlabel ('Socio Economic Status');
%xlabel ('MEAN OPINION SCORE (MOS)');
xlabel ('SCORE');
% Creating a legend and placing it outside the bar plot
lg = legend('MALE','FEMALE','AutoUpdate','off');
lg.Location = 'BestOutside';
lg.Orientation = 'Horizontal';
hold on;
% Finding the number of groups and the number of bars in each group
ngroups = size(model_series, 1);
nbars = size(model_series, 2);
% Calculating the width for each bar group
groupwidth = min(0.8, nbars/(nbars + 1.5));
% Set the position of each error bar in the centre of the main bar
% Based on barweb.m by Bolu Ajiboye from MATLAB File Exchange
for i = 1:nbars
% Calculate center of each bar
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
errorbar(model_series(:,i),x, model_error(:,i),'horizontal','k', 'linestyle', 'none');
end

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by