Axis limits when one bound is set to inf
8 次查看(过去 30 天)
显示 更早的评论
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'
0 个评论
回答(1 个)
dpb
2018-3-4
编辑:dpb
2018-3-4
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 个评论
dpb
2018-3-5
编辑:dpb
2018-3-6
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!