MATLAB: Ensure x label never cut off

bar figure xlabel

I have a bar plot with some x labels that can be fairly lengthy (rotated vertically with rotateticklabel). If left on its own, Matlab cuts off the x labels.
How can I set the figure to "squeeze" the bars so that all of the labels are visible?

Best Answer

A "manual" method of fixing cutoff labels by making the axis smaller is relatively easy to implement. You pick a scale value that makes the labels not be cutoff.
plot(1:10);
scale = 0.9;
pos = get(gca, 'Position');
pos(2) = pos(2)+scale*pos(4);
pos(4) = (1-scale)*pos(4);
set(gca, 'Position', pos)
A more automated solution where you programmatically find the lower edge of the tick labels is more involved. Once you have the lower edge you need to decide if you want to shrink the axis or enlarge the figure. There of course exists the possibility that the tick labels are so long that you cannot shrink the axis enough. A less likely problem is that your tick labels are larger than the screen. This requires another work around ( http://www.mathworks.com/matlabcentral/answers/37318-how-to-save-a-figure-that-is-larger-then-the-screen ).
A fully automated solution is difficult. The easiest solution would be to take the programmatic solution and include it in a modified rotateticklabel.