I am trying to print a sequence of images in a code loop. I will ultimately need to print around 1000 to show how my system varies with time. I have reviewed the methods outlined in Matplotlib runs out of memory when plotting in a loop but I still can't make the code produce more than 96 images or so.
The code I am using in its stripped out form is below
import numpy as np
import matplotlib as mpl
import os
def pltHM(graphname,graphtext,xAxis,yAxis,xMn,xMx,xCnt,yMn,yMx,yCnt,TCrt):
plt = mpl.pyplot
fig = plt.figure(figsize=(8,7), dpi=250)
cmap = mpl.cm.jet
norm = mpl.colors.Normalize(vmin=-3, vmax=3)
X = np.linspace(xMn,xMx,xCnt)
Y = np.linspace(yMn,yMx,yCnt)
plt.xlabel(xAxis)
plt.ylabel(yAxis)
plt.pcolormesh(X,Y,TCrt, cmap=cmap,norm=norm)
plt.grid(color='w')
plt.suptitle(graphtext, fontsize=14)
plt.colorbar()
plt.savefig(graphname, transparent = True)
plt.cla()
plt.clf()
plt.close(fig)
del plt
del fig
return
This is used in a simple loop as shown below
for loop1 in range(0,10):
for loop2 in range(0,100):
saveName = 'Test_Images/' + str(loop1) + '_' + str(loop2) + '.png'
plotHeatMap(saveName,'Test','X','Y',-35,35,141,-30,30,121,Z)
Any advice on why the above is not releasing memory and causing the traceback message
RuntimeError: Could not allocate memory for image
Many thanks for any help provided