Problem with axis equal

조회 수: 359 (최근 30일)
broken_arrow
broken_arrow 2021년 3월 19일
답변: Walter Roberson 2021년 3월 22일
I have a problem with the following code:
inputfigure = figure('Name','Test','Numbertitle','off','Units','centimeters','Position',[5 2 40 23],'Visible','on');
sub2 = subplot('Position',[0.05 0.45 0.2 0.5],'Xdir','reverse');
hold on
grid on
axis equal % this causes the problem
sub2.Layer = 'top';
sub2.Units = 'centimeters';
sub2.Position(4) = sub2.Position(3); % this should make the plot square
The last line should make the plot square, but it only works if I remove axis equal. Why is that? I know I can put 'axis equal' afterwards, but I'd still like to know ;) (As a sidenote, it seems weird that 'subplot' does not accept 'units','centimeters' on creation although the lower level 'axes' command does).
  댓글 수: 2
DGM
DGM 2021년 3월 21일
axis equal
sets the 'PlotBoxAspectRatio' property to a calculated value and sets 'PlotBoxAspectRatioMode' property to 'manual' instead of auto. Changing the position property afterwards doesn't change the aspect ratio since it's in manual mode. Are you sure you don't mean to do something like
axis square
instead?
broken_arrow
broken_arrow 2021년 3월 22일
편집: broken_arrow 2021년 3월 22일
Thanks for explaining. I know about axis square, I just wanted to improve my understanding ;). So what changes if I modify the 'position' property afterwards? The position value is still updated, but what does that nominal change of size actually do if it doesn't really influence the plot size?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 22일
axis equal sets the axes DataAspectRatio to [1 1 1], so that one physical unit in each direction corresponds to one data unit.
It also sets the PlotBoxAspectRatio, which controls the relative ratios of drawing the axes. You can have different sizes of axes drawn while the data to physical ratio might be the same for all three axes.
The PlotBoxAspectRatio is set so as to retain the same data span on the shorter of what x or y was, but accounting for the data units being made uniform. So after axis equal, the visual appearance of the axes is left the same, but the longer of the two distances (in data units) has been adjusted to account for the units now being uniform.
When you set the Position property, the DataAspectRatio is left at [1 1 1], but the PlotBoxAspectRatioMode is set to 'manual' and the PlotBoxAspectRatio reflects the size you set.
Setting axis equal does not constrain the axis Position to be equal x and y span; it constrains the data aspect ratio; and when you set the axis Position manually, it keeps the data aspect ratio in effect.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by