set1limtight

set ylim tight for the current xlim range of a plot (xlim stays unchanged); incl. option for xlim
180 Downloads
Updated 5 Mar 2013

View License

After setting xlim (or zooming), it is sometimes useful to set ylim to the full range of the ydata WITHIN xlim.
ylim([-inf inf]) will set ylim at min(ydata) to max(ydata)."axis tight" does the same, and also sets xlim([min(xdata) max(xdata)]). In both cases ylim is calculated from the full ydata, and not just the ydata that is visible at the current xlim.

set1limtight('y') sets ylim to min and max of the ydata within range xlim. It leaves xlim unchanged.
set1limtight('x') same for xlim
set1limtight('y',ah) sets ylim for axes handle ah

Example:
x = 0:0.1:7; y = [sin(x); sin(x+0.2)*0.95];
plot(x,y,'o-');
xlim([1.15 2.45]);
set1limtight('y')

Cite As

Bart van Oort (2024). set1limtight (https://www.mathworks.com/matlabcentral/fileexchange/40373-set1limtight), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Startup and Shutdown in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.2.0.0

fixed typo in description

1.1.0.0

1) added option to select 'x' or 'y', and to pass an axes handle (passing multiple axes handles is not implemented)
2) added argument/error checks
3) improved help section
4) set1limtight now combines and replaces functions setxtight and setytight

1.0.0.0