Preserve plot box size while updating data aspect ratio

2 ビュー (過去 30 日間)
T A
T A 2022 年 12 月 9 日
編集済み: Varun 2023 年 3 月 20 日
Matlab documentation states that disabling either of the data or plot box aspect ratios turns off stretch-to-fill and causes the axes to immediately resize. However, when changing the data aspect ratio of an axes, I would like the plot box to stay as it is, and instead the XLim and YLim properties to be automatically updated. I have tried several different iterations of the code below, but none have succeeded.
Notably, if the figure window is not docked, then the desired behavior is achieved. And if run line-by-line, then the desired behavior is achieved. But, I'm running some costly figure generation code, so I would rather avoid these less efficient "hacks". I'm using version 2020a, in case it matters.
figure
set(gcf,'windowstyle','docked')
cax=axes;
hold(cax,'on')
cax.YLim=[0,cax.PlotBoxAspectRatio(2)];
cax.PlotBoxAspectRatioMode='manual';
cax.DataAspectRatioMode='manual';
cax.XLimMode='auto';
cax.YLimMode='auto';
cax.DataAspectRatio=[1, 0.5, 1];
  2 件のコメント
J. Alex Lee
J. Alex Lee 2022 年 12 月 10 日
I think you will need to calculate the axes dimensions and manually set them.
Varun
Varun 2023 年 3 月 20 日
編集済み: Varun 2023 年 3 月 20 日
Hello!
Can you please tell me exactly what's going wrong? I ran the code snippet you posted and I got a docked plot of the axes. When I zoomed in on the plot, the plot box does not get resized, and instead the values on the axes changed i.e., the xlim and ylim values got changed. I tried this on both R2022b and R2020a and got the same results. I even tried plotting multiple arrays on the same axes and still, the size does not get affected. So, please let me know exactly how to help!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by