using subplot in bar , how to adjust bar width

조회 수: 20 (최근 30일)
peter huang
peter huang 2022년 10월 2일
답변: Chunru 2022년 10월 2일
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)

답변 (1개)

Chunru
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;

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by