Borrar filtros
Borrar filtros

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

11 visualizaciones (últimos 30 días)
Tim
Tim el 12 de Dic. de 2016
Editada: Guillaume el 14 de Dic. de 2016
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 comentarios
KSSV
KSSV el 13 de Dic. de 2016
Try axis tight and then get the limits.
Tim
Tim el 14 de Dic. de 2016
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.

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 13 de Dic. de 2016
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 comentarios
Stephen23
Stephen23 el 14 de Dic. de 2016
Editada: Stephen23 el 14 de Dic. de 2016
@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 el 14 de Dic. de 2016
Editada: Guillaume el 14 de Dic. de 2016
"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.

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by