How do I extend the margin at the bottom of a figure in Matplotlib?

A quick one-line solution that has worked for me is to use pyplot's auto tight_layout method directly, available in Matplotlib v1.1 onwards:

plt.tight_layout()

This can be invoked immediately before you show the plot (plt.show()), but after your manipulations on the axes (e.g. ticklabel rotations, etc).

This convenience method avoids manipulating individual figures of subplots.

Where plt is the standard pyplot from: import matplotlib.pyplot as plt


fig.savefig('name.png', bbox_inches='tight')

works best for me, since it doesn't reduce the plot size compared to

fig.tight_layout()

Two retroactive ways:

fig, ax = plt.subplots()
# ...
fig.tight_layout()

Or

fig.subplots_adjust(bottom=0.2) # or whatever

Here's a subplots_adjust example: http://matplotlib.org/examples/pylab_examples/subplots_adjust.html

(but I prefer tight_layout)