How do I add space between the ticklabels and the axes in matplotlib

If you don’t want to change the spacing globally (by editing your rcParams), and want a cleaner approach, try this:

ax.tick_params(axis="both", which="major", pad=15)

or for just x axis

ax.tick_params(axis="x", which="major", pad=15)

or the y axis

ax.tick_params(axis="y", which="major", pad=15)

Leave a Comment