Preserve plot box size while updating data aspect ratio

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 2-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