using subplot in bar , how to adjust bar width
조회 수: 8 (최근 30일)
이전 댓글 표시
how to adjust unified bar width in subplot
ex. code
clear all ; clc ;clf
x1 = [1 2 3];
y1 = [1 2 3 ];
x2 = [1 2 3 4 5];
y2 = [1 2 3 4 5];
%%
subplot(211)
bar(x1 ,y1)
subplot(212)
bar(x2 ,y2)
댓글 수: 0
답변 (1개)
Chunru
2022년 10월 2일
x1 = [1 2 3];
y1 = [1 2 3 ];
x2 = [1 2 3 4 5];
y2 = [1 2 3 4 5];
% Make xlim same so that the bar width is the same
h1= subplot(221);
bar(x1 ,y1)
h2 = subplot(222);
bar(x2 ,y2);
set([h1 h2], 'Xlim', [0 6])
% Adjust the bar width
h3=subplot(223);
hbar1=bar(x1 ,y1, 0.8);
h4=subplot(224);
hbar2 = bar(x2 ,y2, 0.8);
xl1 = xlim(h3);
xl2 = xlim(h4);
s = diff(xl2)/diff(xl1);
hbar1.BarWidth = 0.8/s;
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!