get axis limits actually used after assigning [-inf inf -inf inf]
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (1)
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
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
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.
Ver también
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!