ax.margins(some_percentage)
或等效的plt.margins(some_percentage)
。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) # 5% padding in all directions
plt.show()
ax.autoscale(True)
。 - SpinUp __ A Davis