import matplotlib.pyplot as plt
fig = plt.figure()
for n in range(0, 10):
    plt.plot(list(range(0, n)))
fig.savefig('test%d.png' % n)
plt.show()
plt.clf()
Matplotlib: Saved files in a loop aren't the same as in show()