how to adjust bar width (absolute value)?

조회 수: 8 (최근 30일)
Chang seok Ma
Chang seok Ma 2021년 9월 9일
편집: the cyclist 2021년 9월 9일
Hello,
I am trying to plot using two different bar graphs in Matlab
figure(1)
bar(horizon1,data_2001(1:4,2),1,'b','FaceAlpha',0.6)
figure(2)
bar(horizon2,data_2002(1:5,2),1,'b','FaceAlpha',0.6)
I want to keep the width of each bar constant. However, I got something like below
The latter one has wider bar than the former one.
Is there any way I can keep the width consistent?
Thanks in advance.

채택된 답변

the cyclist
the cyclist 2021년 9월 9일
편집: the cyclist 2021년 9월 9일
I would point out that in one sense, your bars are the same width -- they both extend one unit (e.g. from 1.5 to 2.5). The reason their plotted width is different is that your x-axis extents are different.
So, one way to fix this would be to set the x-axis limits and xtick labels manually to be the same for both plots:
x1 = 1:5;
y1 = [100 800 1800 1700 200];
x2 = 1:4;
y2 = [200 1500 1400 400];
figure
bar(x1,y1,1,'b','FaceAlpha',0.6)
set(gca,'XLim',[0 6],'XTick',0:6)
figure
bar(x2,y2,1,'b','FaceAlpha',0.6)
set(gca,'XLim',[0 6],'XTick',0:6)

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by