I\'d like to create different figures in Python using matplotlib.pyplot
. I\'d then like to save some of them to a file, while others should be shown on-screen using
The better way is to use plt.clf()
instead of plt.close()
.
Moreover plt.figure()
creates a new graph while you can just clear previous one with plt.clf()
:
import matplotlib.pyplot as plt
y1 = [4, 2, 7, 3]
y2 = [-7, 0, -1, -3]
plt.figure()
plt.plot(y1)
plt.savefig('figure1.png')
plt.clf()
plt.plot(y2)
plt.show()
plt.clf()
This code will not generate errors or warnings such can't invoke "event" command...