ループで画像をプロットすると、メモリの問題が発生します。古いものを削除するにはどうすればよいですか?
エラー:
Traceback (most recent call last):
File "C:\Users\Alex\Dropbox\code stuff\solarsystem.py", line 69, in <module>
fig = plt.figure()
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 343, in figure
**kwargs)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 79, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 106, in new_figure_manager_given_figure
canvas = FigureCanvasTkAgg(figure, master=window)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 225, in __init__
master=self._tkcanvas, width=w, height=h)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3306, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 3262, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: not enough free memory for image buffer
脚本:
count = 0
xy = bodies[0][2]
x = [[a[0] for a in bodies[0][2]]]
y = [[a[1] for a in bodies[0][2]]]
z = [[a[2] for a in bodies[0][2]]]
for i in range(1,nbodies):
x.append([a[0] for a in bodies[i][2]])
y.append([a[1] for a in bodies[i][2]])
z.append([a[2] for a in bodies[i][2]])
for j in range(0,len(bodies[0][2])-1,10):
Xc = [[x[0][j]]]
Yc = [[y[0][j]]]
Zc = [[z[0][j]]]
for k in range(1,nbodies):
Xc.append([x[k][j]])
Yc.append([y[k][j]])
Zc.append([z[k][j]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for l in range(len(Xc)):
ax.scatter( Xc[l], Yc[l], Zc[l], c=(i/nbodies,i/nbodies,i/nbodies))
ax.axis([-400, 400, -400, 400])
ax.set_zlim(-400, 400)
pylab.savefig('images/img'+str(count))
pylab.clf()
count += 1
percent = (j/(len(bodies[0][2])-1.))*100
if percent % 10 ==0:
print percent