I want to create a lot, at least 10000 plot, so I use for loop to do it, Here is my code.
for i in range(0, 10000):
fig, ax = plt.subplots(1, 1, num=0)
x = np.linspace(0, 100, 100)
y = np.sin(x)
ax.plot(x, y)
plt.tight_layout()
fig.savefig("test.png")
plt.close(fig=0)
def plot_test():
for i in range(0, 10000):
fig, ax = plt.subplots(1, 1, num=0)
x = np.linspace(0, 100, 100)
y = np.sin(x)
ax.plot(x, y)
plt.tight_layout()
fig.savefig("test.png")
plt.close(fig=0)
No matter use plt.close() in function or outside, The memory is still increasing, I have checked plt.close("all") and plt.close(fig) are not working too. Hope anyone can tell me how to use plt.close() properly.