I have a little problem with matplotlib. When trying to save several digits in a loop a hundred times with savefig() , it finally ends with the following error:
IOError: [Errno 24] Too many open files: 'test_421.png'
I checked that after each save of the figure I close it, but it does not seem to be effective.
Here is a sample code to illustrate how I get this error:
def displayFig(input, display, savePath): fig = plt.figure(figsize=(22, 5)) # add some subplots, axis and colorbars... if display: plt.show() else: plt.savefig(savePath, dpi = 100) plt.close(fig) for i, inp in enumerate(inpArray): savePath = 'test_%d.png' % i displayFig(inp, False, savePath)
Why does this error occur? Maybe this is a multithreading problem or a memory leak?
source share