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')
jh314
  • 27,144
  • 16
  • 62
  • 82
vdogsandman
  • 5,289
  • 8
  • 21
  • 21
  • There's better ways to do this, but if you changed `s=str(image + 'IMAGE' + str(i))` to `s=str(image) + 'IMAGE' + str(i) + '.png'` it might do what you want? – bbayles Jun 28 '13 at 22:08

1 Answers1

0

In a more pythonic way

s = "%sIMAGE%d.png" % (image, i)
jonnybazookatone
  • 2,188
  • 15
  • 21