Matplotlib "snaps" plot limits to "whole" (factors of 2, 5, 10, 100, etc) numbers, by default. This often means that your data may wind up on the boundary of the plot.
ax.margins
allows you to add a padding factor before this autoscaling for the plot is calculated. It's a quick way to avoid the problem of points on the plot boundary.
As a quick example of the problem:
import matplotlib.pyplot as plt
x, y = [0, 10, 20], [10, 0, 0]
fig, ax = plt.subplots()
ax.plot(x, y, 'ko')
plt.show()
And an easy solution:
import matplotlib.pyplot as plt
x, y = [0, 10, 20], [10, 0, 0]
fig, ax = plt.subplots()
ax.plot(x, y, 'ko')
# Pad by 5% of the data range before autoscaling:
ax.margins(0.05)
plt.show()