필터 지우기
필터 지우기

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 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