In your case, it is easiest to use ax.margins(some_percentage)or equivalent plt.margins(some_percentage).
For example:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = np.linspace(0, 1)
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
ax.plot(x, y, 'r')
ax.grid(True)
ax.margins(0.05)
plt.show()

source
share