pythonmatplotlibxticksyticks

How do I add space between the ticklabels and the axes


I've increased the font of my ticklabels successfully, but now they're too close to the axis. I'd like to add a little breathing room between the ticklabels and the axis.


Solution

  • It looks like matplotlib respects these settings as rcParams:

    pylab.rcParams['xtick.major.pad']='8'
    pylab.rcParams['ytick.major.pad']='8'
    

    Set those before you create any figures and you should be fine.

    I've looked at the source code and there doesn't appear to be any other way to set them programmatically. (tick.set_pad() looks like it tries to do the right thing, but the padding seems to be set when the Ticks are constructed and can't be changed after that.)