Fix Python – Matplotlib – Move X-Axis label downwards, but not X-Axis Ticks

Question

Asked By – victorhooi

I’m using Matplotlib to plot a histogram.
Using tips from my previous question: Matplotlib – label each bin,
I’ve more or less go the kinks worked out.

There’s one final issue – previously – the x-axis label (“Time (in milliseconds)”) was being rendered underneath the x-axis tickmarks (0.00, 0.04, 0.08, 0.12 etc.)

No padding - Axis label underneath figures

Using the advice from Joe Kingston (see question above), I tried using:

ax.tick_params(axis='x', pad=30)

However, this moves both the x-axis tickmarks (0.00, 0.04, 0.08, 0.12 etc.), as well as the x-axis label (“Time (in milliseconds)”):

30 Padding - Both Axis Label and Tick Marks have Moved

Is there any way to move only the x-axis label to underneath the three rows of figures?

Nb: You may need to open the PNGs below directly – Right Click on the image, then View Image (in FF), or Open image in new tab (Chrome). The image resize done by SO has rendered them nigh unreadable

Now we will see solution for issue: Matplotlib – Move X-Axis label downwards, but not X-Axis Ticks


Answer

use labelpad parameter:

pl.xlabel("...", labelpad=20)

or set it after:

ax.xaxis.labelpad = 20

This question is answered By – HYRY

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0