Set aspect ratio in tilelayout
Ältere Kommentare anzeigen
When I run this code, the two plots are not each "square" (aspect ratio 1:1)
function [] = plotSVD( A )
A = [1, 2; 0, 2];
theta = linspace(0,2*pi, 1000);
x1 = cos(theta);
y1 = sin(theta);
tempBecauseMatlabIsStupid = A*[x1;y1];
x2 = tempBecauseMatlabIsStupid(1,:);
y2 = tempBecauseMatlabIsStupid(2,:);
% Two plots
tiledlayout(1,2) % Requires R2019b or later
ax1 = nexttile;
pbaspect(ax1,[1 1 1]); % doesn't do anything
axis equal; % doesn't do anything
plot(ax1,x1,y1)
ax2 = nexttile;
pbaspect(ax2,[1 1 1]); % doesn't do anything
axis equal; % doesn't do anything
plot(ax2,x2,y2)
end
Currently, to make them "square", I have to manually adjust the width of the window.
How can I make MATLAB print them "square"? Ideally, I'd like the figure to show in a window AND save to a PDF, with each of the two plots in the figure having an aspect ratio of 1:1
3 Kommentare
Adam Danz
am 20 Sep. 2020
"axis equal; % doesn't do anything"
axis equal does exactly what it's supposed to do - it equates the length of the data units along the axes.
What you're looking for is axis square which will equate the lengths of the axes but will not equate the axis units so a circle may not appear as a circle.
If you want both, you can set axis equal and then set the ylim and xlim ranges to be the same.
Joseph Pedersen
am 21 Sep. 2020
That's because you are applying it incorrectly.
"% doesn't do anything"
Those lines are doing exactly what they should be doing but you're losing those settings when you plot data to the axes.
See my answer for the correct way to apply these settings.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Axes Appearance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



