How to get accurate DataAspectRatio when stretch-to-fit is enabled?

3 ビュー (過去 30 日間)
Evan
Evan 2017 年 2 月 21 日
回答済み: Evan 2017 年 3 月 24 日
Matlab documentation states that when stretch-to-fill is enabled (as it is by default), then "the axes might not exactly match the data aspect ratio, plot box aspect ratio, and camera-view angle values stored in its DataAspectRatio, PlotBoxAspectRatio, and CameraViewAngle properties." Setting the 'mode' of any one of these three properties to 'manual' should turn off stretch-to-fill. My issue is that I want an accurate reading of the DataAspectRatio without setting any of these to manual. A workaround seems to be temporarily setting PlotBoxAspectRatioMode to 'manual,' which has the effect of changing the value of DataAspectRatio to match what is on screen [1].
figure;plot(0.1:0.1:pi,sin(0.1:0.1:pi))
pbaspect manual
val = daspect
pbaspect auto
Or a safer way to do it if you want a generally useful script (e.g. in case PlotBoxAspectRatioMode is already manual and you don't want to change that) would be:
pbaspectMode = get(gca,'PlotBoxAspectRatioMode');
pbaspect manual;
val = daspect;
set(gca,'PlotBoxAspectRatioMode',pbaspectMode);
My question is - is this safe? Or will there be side effects, either occurring intermittently, or that are hard to detect?
[1] This is in contrast to as setting DataAspectRatioMode to 'manual,' which changes what's on screen to match the current value of DataAspectRatio. This is not what I want.

採用された回答

Evan
Evan 2017 年 3 月 24 日
From Mathworks support:
The technique of setting bpaspect to manual and then back may be "safe" (although I wouldn't be surprised if there are side effects), but a better way is to divide:
real_daspect = daspect./pbaspect;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePlot Customization についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by