Axis limits when one bound is set to inf

15 vues (au cours des 30 derniers jours)
jg
jg le 3 Mar 2018
Modifié(e) : dpb le 6 Mar 2018
How do you return the limits of the axis when one of the bounds is -inf/inf?
From Matlab's documentation, consider:
[X,Y,Z] = peaks;
surf(X,Y,Z)
ylim([0 inf])
How would you find out what the y limits ended up at? YLim simply returns [0 inf]. I'm surprised they have no way of telling you what the actual axis limits are.
I tried temporarily setting YLimMode to 'auto', finding the limits, then setting back, but this does not work. Setting
axes.YLim = [0 inf]
Will result in a different upper bound than
axes.YLimMode = 'auto'

Réponses (1)

dpb
dpb le 4 Mar 2018
Modifié(e) : dpb le 4 Mar 2018
Have to allow as how I've never set an axis limit to +/-Inf...not having that large of a monitor. :)
I didn't go look and see if it's documented; given the behavior of
>> y=(randn(5,1));
>> plot(y)
>> ylim([0 inf])
>> max(y(:))
ans =
3.58
>> get(gca,'YTick')
ans =
0 0.50 1.00 1.50 2.00 2.50 3.00 3.50
>> ylim
ans =
0 Inf
>>
it appears that since the outer bounding box touches the maximum y value at the top of the plot and that is just a little past where the 3.5 tick value is that
ylim([-Inf Inf])
is shorthand for
ylim([min(y(:)) max(y(:))])
and so the best answer to the original question is to query the data for appropriate bounding direction instead of querying the axes properties themselves.
There may be a hidden property that is used internally; that I also did not explore.
If you can't find the above behavior documented, I'd suggest an enhancement request to the documentation to that effect (or whatever TMW confirms is actual behavior if different in some detail).
  2 commentaires
jg
jg le 5 Mar 2018
I agree, I could calculate the limits of the plotted data, but that is too inefficient if I have a lot of data plotted. I'd have to grab all the line objects plotted on that axes, then find the global min/max. The data I want has to exist somewhere already.
dpb
dpb le 5 Mar 2018
Modifié(e) : dpb le 6 Mar 2018
Doesn't mean it's exposed, however....
Unless there's way more data being plotted than should be(*), shouldn't be that bad; easy enough to put into a function.
You can look for hidden properties by using File Exchange tool <Fileexchange/32934-getundoc-get-undocumented-object-properties> and go spelunking.
(*) As in the occasional case one finds of plotting a full time trace of 1M points when there's only something like a few K pixels on the screen.

Connectez-vous pour commenter.

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by