R plots automatically set the x and y limits to put some space between the data and the axes. I was wondering if there is a way for matplotlib to do the same automatically. If not, is there a good formula or 'rule of thumb' for how R sets its axis limits?
In matplotlib you can achieve this by setting the margins
import matplotlib.pyplot as plt fig, ax = plt.subplots()
ax.margins(0.04)
data = range(1, 11)
ax.plot(data, 'wo')
plt.savefig('margins.png')
However, it doesn't seems, that there is an rc parameter to get this automatically.
Update 4/2013
The possibility to add an rc param for the margins is now in matplotlib master
(Thanks @tcaswell).
So it should work with the next matplotlib release (current release is 1.2.1).