I am trying to save a Matplotlib figure as a file from an iPython notebook.
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes([1,1,1,1])
ax.plot([1,2])
fig.savefig('test.png')
The inline view in the iPython notebook looks good:

The file 'test.png' is almost empty though. It looks like the plot is shifted to the top right, you can see the tick labels '1.0' and '0.0' in the corner.

How can I produce a file from the iPython notebook that looks like the inline view?