Filter löschen
Filter löschen

using subplot in bar , how to adjust bar width

8 Ansichten (letzte 30 Tage)
peter huang
peter huang am 2 Okt. 2022
Beantwortet: Chunru am 2 Okt. 2022
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)

Antworten (1)

Chunru
Chunru am 2 Okt. 2022
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;

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by