필터 지우기
필터 지우기

How can I query the default automatic axis limits chosen by MATLAB in advance of plotting?

조회 수: 5 (최근 30일)
I know that I can query the xlim values that Matlab uses for a plot, e.g. as in the code below.
xvals = [1.13 2 3 4.5];
yvals = [1 2 3 4];
plot(xvals, yvals, 'o')
xlim tickaligned % set the intented mode, other: tight or padded
forLaterUse = xlim; % get the limits for later use; here 1.0 4.5
How can I query these limits without executing the plot-command? I need something like:
forLaterUse = xlim(xvals, 'tickaligned');

채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 8일
xlim auto is not calculated until the plot is made visible, such as by drawnow(). It needs to have all of the XData for all objects in the axes in order to be able to find min and max. If you have not plotted yet you could only query the current settings, or set the xlim manually according to what you know about the span of data to plot
  댓글 수: 2
Walter Roberson
Walter Roberson 2021년 9월 8일
Note that xlim auto is not updated as you add new items to the axes, not until it is time to render the plot.
There is no documented way to ask what the limits would be if you were to render now: you have to force a render (possibly followed by making the graphics objects invisible again if you are not ready for them to show up.)
Jürgen
Jürgen 2021년 9월 8일
I understand the answers and different options and know how to work around or to code my own niceAxisLimits(xVals, mode)-function. I judge the answer as accepted but still kind of suggestion for improvment because there is further use of such and related functionality in plotting-topics (e.g. adding second functionally aligned axis...).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by