Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 411
abjennings Avatar asked Jun 03 '10 21:06

abjennings


People also ask

How do I increase spacing in Matplotlib?

We can use the plt. subplots_adjust() method to change the space between Matplotlib subplots. The parameters wspace and hspace specify the space reserved between Matplotlib subplots. They are the fractions of axis width and height, respectively.

What is padding in Matplotlib?

pad: This parameter is used for padding between the figure edge and the edges of subplots, as a fraction of the font size. h_pad, w_pad: These parameter are used for padding (height/width) between edges of adjacent subplots, as a fraction of the font size.

What are the two ways to adjust axis limits of the plot using Matplotlib?

Adjust axis limits: To set the limits of x and y axes, we use the commands plt. xlim() and plt. ylim().


1 Answers

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)

like image 168
wronk Avatar answered Oct 23 '22 12:10

wronk