Search code examples
matlabplotmatlab-figure

Prevent data from touching axes


In MATLAB, is it possible to quickly/concisely increase the default padding around data in plots? In other words, I don't want the data to be too close to the axes.

enter image description here


Solution

  • If simply padding the existing axis is sufficient then the following should work. Say you want to add 10% to each side.

    plot(...);
    scale = 1.1;
    ax = axis();
    xc = 0.5 * (ax(1)+ax(2));
    yc = 0.5 * (ax(3)+ax(4));
    c = [xc,xc,yc,yc];
    axis(scale * (ax - c) + c);