Problem with axis equal

387 ビュー (過去 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 Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by