Standard deviation error bars not in the centre of the bar

조회 수: 15 (최근 30일)
Daniel Underwood
Daniel Underwood 2020년 7월 29일
댓글: Daniel Underwood 2020년 7월 29일
So I have produced a bar chart for some preliminary data, and attempted to plot error bars with the value of 1SD (see below). However, not all my error bars have there middle on the top of my columns, some appearing asymetrical and others appearing within the bar itself. What have I done wrong here?
%Insert data
data = [20000 0 200; 0 400 1200; 1400 200 2400; 200 400 3400];
%Group titles
titles = categorical({'C 10:1', 'U 10:1', 'U 30:1', 'U 100:1'});
%Calculate Mean and Standard Deviation
average = mean(data,2);
S = std(data,[],2);
%Plot bar chart
attempt2 = bar(titles,average,'FaceColor','none');
hold on
%Make SD error bars
eb = errorbar(average,S,'Color','black');
eb.LineStyle = 'none';
% Chart details
title('CFU Exp 1, 21/07/2020 Error bars = 1SD')
xlabel('Coated or Uncoated MOI')
ylabel('No. of bacteria')
hold off

채택된 답변

Johannes Hougaard
Johannes Hougaard 2020년 7월 29일
You're just missing the y input for your errorbar. I belileve your problem will be solved by just replacing
eb = errorbar(average,S,'Color','black');
with
eb = errorbar(titles,average,S,'Color','black');
  댓글 수: 1
Daniel Underwood
Daniel Underwood 2020년 7월 29일
Thank you very much. I excluded "titles" as I thought added a categorical array would cause more problems. Turns out it was the solution!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by