Set aspect ratio in tilelayout
이전 댓글 표시
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
Adam Danz
2020년 9월 20일
"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
2020년 9월 21일
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Axes Appearance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



