How to change separation between tick labels and axis labels in Matplotlib

drastega picture drastega · Feb 3, 2014 · Viewed 20.4k times · Source

My axis labels often look not good (too close to tick labels) when I use Matplotlib.

test image

How to set distance between tick labels and axis label? I just need to enlarge distance between "Number of stars" label and corresponding tick labels. Maybe latex \vspace{} is working but I don't know how to implement it. fig.subplots_adjust(left=) is not a solution.

Answer

sodd picture sodd · Feb 5, 2014

To move the axis label further away from the axis, you can include an argument to the optional labelpad parameter of the corresponding method used to set the label, i.e. ax.set_ylabel() or ax.set_xlabel(). This parameter takes a scalar which is the spacing between the axis and the label given in points.

As to achieve the same effect when using the drawparallels() method of Basemap, I believe you can include an argument to the parameters xoffset or yoffset, depending on which axis you want to alter the placement of the text. The arguments of these parameters have "units" of map width, meaning e.g. xoffset=0.05 makes the offset of the x-ticks 5 % of the map width.