Search code examples
matlabplotmatlab-figure

Change the space between the ticklabels and axes (same for ticklabel and ylabel or xlabel) in matlab


How do I change space between the ticklabels and the axes (s2), same for ticklabel and ylabel or xlabel (s1, s3) in matlab (I using matlab 2015b).

enter image description here


Solution

  • If you read the documentation for xlabel and ylabel you will see that you can specify the optional output argument to return a Text object, which you can use to access and modify the properties of the label after it has been created.

    Of interest here is the 'Position' property of the label, which is an [x y z*] position vector (z is optional). For example:

    plot(1:10);
    xl = xlabel('An X Label');
    yl = ylabel('A Y Label');
    

    Generates the following:

    before

    Which we can then adjust:

    xl.Position(2) = 0.15;  % Shift x label down
    yl.Position(1) = 0.20;  % Shift y label left
    

    after

    As far as I can remember I don't believe there's a simple way to adjust the tick offset.