Effacer les filtres
Effacer les filtres

using subplot in bar , how to adjust bar width

8 vues (au cours des 30 derniers jours)
peter huang
peter huang le 2 Oct 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)

Réponses (1)

Chunru
Chunru le 2 Oct 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;

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by