Tuesday, 13 August 2013

Matplotlib crashes after saving many plots

Matplotlib crashes after saving many plots

I am plotting and saving thousands of files for later animation in a loop
like so:
import matplotlib.pyplot as plt
for i in results:
for j in result:
plt.figure()
plt.plot(j) # this changes
plt.xlabel('xlabel') # this doesn't change
plt.ylabel('ylabel') # this doesn't change
plt.title('title') # this changes
plt.ylim([0,1]) # this doesn't change
plt.grid(True) # this doesn't change
plt.savefig(location, bbox_inches=0) # this changes
When I run this with a lot of results, it crashes after several thousand
plots are saved. I think what I want to do is reuse my axes like in this
answer: http://stackoverflow.com/a/11688881/354979 but I don't understand
how. How can I optimize it?

No comments:

Post a Comment