Forcing two subplots to have the same width
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
David Aronstein
am 17 Aug. 2014
Kommentiert: Star Strider
am 18 Aug. 2014
In the simple script below, I create two matrices, having different numbers of rows but the same number of columns:
m1 = rand(64, 512);
m2 = rand(128, 512);
h=figure;
subplot(2,1,1);
imagesc(m1);
axis equal;
xlim([1, 512]);
ylim([1, 64]);
title('64x512');
subplot(2,1,2);
imagesc(m2);
axis equal;
xlim([1, 512]);
ylim([1, 128]);
title('128x512');
set(h, 'Position', [100, 100, 800, 300]);
In the last line, when the figure size/aspect ratio is changed, the top image is rendered wider in the figure than the bottom image.
How can I set things up so that the two images are drawn with the same WIDTH, regardless of how the figure size/position is adjusted, while preserving the "axis equal" -- that the bottom figure is drawn with 2x the height of the top figure?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 17 Aug. 2014
You have to increase the figure height to accommodate the change, then set the height of subplot(2,1,2) to 2x the height of subplot(2,1,1):
m1 = rand(64, 512);
m2 = rand(128, 512);
h=figure;
set(h, 'Position', [100, 100, 800, 600]); % <— ‘Height’ Increased
subplot(2,1,1);
imagesc(m1);
axis equal;
xlim([1, 512]);
ylim([1, 64]);
title('64x512');
hsp1 = get(gca, 'Position') % Get 'Position' for (2,1,1)
subplot(2,1,2);
imagesc(m2);
axis equal;
xlim([1, 512]);
ylim([1, 128]);
title('128x512');
hsp2 = get(gca, 'Position') % Get 'Position' for (2,1,2)
set(gca, 'Position', [hsp2(1:3) 2*hsp1(4)]) % Use 2*(2,1,1) Height for (2,1,2)
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots 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!