|
From: <aur...@fr...> - 2006-02-08 11:57:48
|
Hi folks,
I have a question I couldn't solve so far. I'm trying to generate say 500=
images
(png) without displaying them using imshow. I wrote a simple test functio=
n
(see below) which I call from a loop in which I create the data for the i=
mage in
a sequence. I systematically bump into a runtime error after saving about=
188
files. After reading the (excellent) tutorial from Perry Greenfield and
Robert Jedrzejewski on interactive data analysis, I understand the need t=
o clean
up by freeing memory but I must be missing something else.
Cheers,
Aur=E9lien
def generateImshow(yarray,
xscansize,yscansize,
xscanstep,yscanstep,
outputfilename,
initimagesize =3D 10):
'''Use this function to generate matplotlib images without displaying
them'''
#reshape according to scan
yarray =3D na.reshape(yarray,(yscansize,-1))
#build image via matplotlib
ximagesize =3D xscansize*xscanstep
yimagesize =3D yscansize*yscanstep
xyimageratio =3D float(ximagesize)/yimagesize
print xyimageratio
if xyimageratio > 1: ximagesize,yimagesize =3D
initimagesize,initimagesize*xyimageratio
else: ximagesize,yimagesize =3D initimagesize*xyimageratio,initimages=
ize
fig1 =3D pylab.figure(figsize=3D(ximagesize,yimagesize),dpi=3D100)
#pylab.title('blahblah')
im1 =3D pylab.imshow(yarray,
origin=3D'lower',
#aspect=3D'preserve',
#interpolation=3D'nearest', #i.e. pixel
interpolation=3D'bicubic', #i.e. smooth
#cmap=3Dmpl.cm.jet, #not correct
#vmin=3Dminvalue,
#vmax=3Dmaxvalue
)
pylab.colorbar()
pylab.bone()
pylab.axis('off')
#save figure
#outputfilename =3D filename[:-4]+'.png'
pylab.savefig(outputfilename)
#pylab.cla()
del im1
pylab.close('all')
|