필터 지우기
필터 지우기

get axis limits actually used after assigning [-inf inf -inf inf]

조회 수: 11 (최근 30일)
Tim
Tim 2016년 12월 12일
편집: Guillaume 2016년 12월 14일
My script is written to use either [-inf inf -inf inf] or an assigned set of axis limits as a variable since the script may instead compute a desired set of limits to be applied as the limit set. I need to know the limits that are actually used in order to add text to the graph. If I assign specific limits to the axis as a variable (computed or manually assigned), no problem. But if [-inf inf -inf inf] is used as the variable, any inquiry as to the actual limits used < get(gca,'ylim') > after plotting and before adding the text, the values returned are [-inf inf], not the actual values. How do I get the values actually used when [-inf inf -inf inf] is the default input?
  댓글 수: 3
KSSV
KSSV 2016년 12월 13일
Try axis tight and then get the limits.
Tim
Tim 2016년 12월 14일
Yeah, The reason I use +/- inf is because I have assigned a variable name to the values so that I can use the script to assign values (or not). When I haven't computed values in the script or want to override, I can easily manually assign the values at the beginning of the script. Otherwise I have to fill the variable with something... +/- inf works as the variable to set it to "default auto scaling", but then I can't get the scaling used.

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

답변 (1개)

Steven Lord
Steven Lord 2016년 12월 13일
If you want to let MATLAB automatically determine the limits, don't set the limits to plus or minus infinity. Instead set the axes property XLimMode to 'auto'. Once MATLAB has computed the limits, get the limits via the XLim axes property or the xlim function.
  댓글 수: 3
Stephen23
Stephen23 2016년 12월 14일
편집: Stephen23 2016년 12월 14일
@Tim: what you are doing is very indirect, and now you are finding out that it has disadvantages too. Good program design does not mean "use lots of code shortcuts". Doing so will not make your code more reliable nor make it easier to write, and it certainly will not make it easier to debug. Good code practices do include using features to do the things that they were designed to do.
If you want auto axis limits then set XLimMode: this is what it is designed for.
Guillaume
Guillaume 2016년 12월 14일
편집: Guillaume 2016년 12월 14일
"If you want auto axis limits then set XLimMode: this is what it is designed for."
...and with the current design is trivial to implement anyway:
%... some code
hax = gca; %should actually be obtained when the axis is created. Using gca is dangerous
if all(isinf(mylimits))
hax.XLimMode = 'auto';
else
hax.Xlim = mylimits;
end
%...
However, I do agree that there should be a way to retrieve the actual axis limits when one or both are set to +/-Inf. XLimMode 'auto' is not going to work when you only want one of the limit on auto.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by