How to access displayed axis limits when scaling is logarithmic and data partly negative?
11 views (last 30 days)
I plot data. Some of the data are quite noisy and occasionally negative values appear, but I'm not interested in them. I apply a logarithmic y-axis scaling. Matlab issues a warning, that 'Negative data are ignored'. I use axis tight which adjusts the axes limits so that the displayed data (i.e. only the positive data!) just fit into the axes.
Now here's my question: How can I access the displayed y-limits?
get(axes_handle, 'YLim') returns the limits of all the data (positive and negative), so that the upper limit matches the displayed upper limit but the lower limit (negative) does not!
Here's a small example:
data = [-1 10 100 1000];
The displayed y-limits are [10 1000] but ylim returns [-1 1000].
Anyone know a solution?
Matt Tearle on 28 Mar 2012
A hack would be to use the YTick values instead, as there's always a tick at the top and the bottom by default.
yl = get(gca,'YTick');
yl = yl([1,end])