0

This code is basically looping through the length of an array (ra_new), and creating plots of the images (given by the equations coded below). Because the array is really long (and thusly there are lots and lots of plots), I am trying to make Python save them as a generic name that's easily readable. In other words, if the name of the file that I input (I didn't show that code, for simplicity) is "googlypants", I want the code to loop through that and save the file as "GooglypantsIMAGE1". I ALSO need it saved as a png or jpeg.

Can somebody please tell me where my mistake is? At the moment, the code is saving as a "GooglypantsIMAGEi" (where i is the element in the arra), which is of course a file extension that doesn't really exist.

for i in range(0,len(ra_new)):
    ra_new2=cat['ra'][z&lmass&ra&dec][i]
    dec_new2=cat['dec'][z&lmass&ra&dec][i]
    target_pixel_x = ((ra_new2-ra_ref)/(pixel_size_x))+reference_pixel_x     
    target_pixel_y = ((dec_new2-dec_ref)/(pixel_size_y))+reference_pixel_y      
    galaxy=plt.imshow(img[target_pixel_x-200:target_pixel_x+100, target_pixel_y-  200:target_pixel_y+100], vmin=-0.01, vmax=0.1, cmap='Greys')
    plt.show()
    s=str(image + 'IMAGE' + str(i))
    pylab.savefig(s,format='png')
4

1 に答える 1

0

よりpythonicな方法で

s = "%sIMAGE%d.png" % (image, i)
于 2014-06-10T16:43:31.563 に答える