필터 지우기
필터 지우기

Error bars centered at one bar in multi-bar plot

조회 수: 12 (최근 30일)
Josefine Olsson
Josefine Olsson 2023년 5월 23일
댓글: Star Strider 2023년 5월 23일
Hi!
How to I get the error bars to show up at the correct bar and not centered as in the figure below? My y-matrix a 4x7.
Thanks!
name = {'Baseline';'Retro';'Tech';'Sub'};
x = [1:4]
figure
hb = bar(x,y);
set(gca,'xticklabel',name)
hold on
errorbar(x,y,errorminus,errorplus,'.k') % the y means (assumes columns are observations)
hold on
p = plot(x,t,'-o','color','k');
ylabel('Bton CO_2e');
hb(1).FaceColor = '#f46d43';
hb(2).FaceColor = '#fdae61';
hb(3).FaceColor = '#ffffbf';
hb(4).FaceColor = '#abdda4';
hb(5).FaceColor = '#66c2a5';
hb(6).FaceColor = '#3288bd';
legend('FC', 'CK', 'ZZ', 'HK', 'VSBK', 'TK')
  댓글 수: 1
Matt J
Matt J 2023년 5월 23일
편집: Matt J 2023년 5월 23일
You code does not run,
name = {'Baseline';'Retro';'Tech';'Sub'};
x = [1:4]
x = 1×4
1 2 3 4
figure
hb = bar(x,y);
Unrecognized function or variable 'y'.
set(gca,'xticklabel',name)
hold on
errorbar(x,y,errorminus,errorplus,'.k') % the y means (assumes columns are observations)

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

채택된 답변

Star Strider
Star Strider 2023년 5월 23일
It would help to have your data matrices. Use XEndPoints and YEndPoints to specify the ends of the bars.
y = rand(5,4);
errorplus = rand(5,4)/10;
errorminus = rand(5,4)/10;
name = {'Baseline';'Retro';'Tech';'Sub'};
x = [1:4];
t = rand(size(x));
figure
hb = bar(x,y);
set(gca,'xticklabel',name)
hold on
for k = 1:numel(hb)
XEP(k,:) = hb(k).XEndPoints;
YEP(k,:) = hb(k).YEndPoints;
errorbar(XEP(k,:),YEP(k,:),errorminus(k,:),errorplus(k,:),'.k') % the y means (assumes columns are observations)
end
hold on
p = plot(x,t,'-o','color','k');
ylabel('Bton CO_2e');
hb(1).FaceColor = '#f46d43';
hb(2).FaceColor = '#fdae61';
hb(3).FaceColor = '#ffffbf';
hb(4).FaceColor = '#abdda4';
hb(5).FaceColor = '#66c2a5';
hb(6).FaceColor = '#3288bd';
Unrecognized property 'FaceColor' for class 'matlab.graphics.GraphicsPlaceholder'.
.
  댓글 수: 2
Josefine Olsson
Josefine Olsson 2023년 5월 23일
Thank you so much!
Star Strider
Star Strider 2023년 5월 23일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by