how to use the "tight" function for just one axis
737 views (last 30 days)
Show older comments
Jamie Shelley on 14 Jul 2016
Commented: ADSW121365 on 31 Aug 2022
So I origionally had: axis tight But it cut both axes, whereas I just want it to be tight around the x axis but allow the y axis to not be cut. Is there a function for this please? Thanks
dpb on 14 Jul 2016
Not at hand, but it's not difficult to do...
% Set axis tight only on y-axes
yl=xlim(ax); % retrieve auto y-limits
axis tight % set tight range
ylim(ax,yl) % restore y limits
You can also actually compute min, max of X-axis data and just set it, which is what is done
xlim can actually do this without manually setting the limits:
which I have added as a seperate answer below.
More Answers (2)
Jaromir on 16 Mar 2018
There's an out-of-the-box command for what you want:
set(handleToAxes, 'XLimSpec', 'Tight');
set(handleToAxes, 'YLimSpec', 'Tight');
Find more on Axes Appearance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!