title: vmin vmax algorithm matplotlib
body: <p>I write script for calibration of image (dark frame and flat field)...Here is part of code</p>
  
  <pre><code>for n in range(len(img)):
    with pyfits.open(img[n], mode='update', memmap=True) as im:
      imgg = im[0].data
      header = im[0].header
      imgg.astype(float)
      imgg = (imgg - dd) / df
      imgg[np.isnan(imgg)] = 1
      imgg.astype(int)
      plt.imshow(imgg, cmap=plt.cm.Greys_r, vmin=0.5, vmax=1.5)
      plt.show()
  </code></pre>
  
  <p>This part of code make calibration of image with dark frame and flat field... When I use at the plotting <code>vmin</code> and <code>vmax</code>, I get the right picture but I don't know how <code>vmin</code> and <code>vmax</code> work. I need to apply this on image data (<code>imgg</code>) because when I save data I get images without <code>vmin</code> and <code>vmax</code>...</p>
  
  <p>Any suggestions?</p>
  
  <p>And the second question... How I can save data changes in fits files? When I used <code>im.close()</code> this work only on one file but don't work in loop. </p>
  
  <p>Thanks</p>
  
  <p>edit</p>
  
  <p>OK here is full script</p>
  
  <pre><code>import numpy as np
  import pyfits
  from matplotlib import pyplot as plt
  import glob
  
  
  dark=glob.glob('.../ha/dark/*.fits')
  flat=glob.glob('.../ha/flat/*.fits')
  img=glob.glob('.../ha/*.fits')
  
  sumd0 = pyfits.open(dark[0])
  sumdd=sumd0[0].data
  sumdd.astype(float)
  for i in range(1,len(dark)):
       sumdi=pyfits.open(dark[i])
       sumdi=sumdi[0].data
       sumdd=sumdd.astype(float)+sumdi.astype(float)
  dd=sumdd/len(dark)
  
  sumf0 = pyfits.open(flat[0])
  sumff=sumf0[0].data
  sumff.astype(float)
  for i in range(1,len(flat)):
       sumfi=pyfits.open(flat[i])
       sumfi=sumfi[0].data
       sumff=sumff.astype(float)+sumfi.astype(float)
  
  ff=sumff/len(flat)
  
  df=(ff-dd)
  
  for n in range(len(img)):
      with pyfits.open(img[n],mode='update',memmap=True) as im:
          imgg=im[0].data
          header=im[0].header
          imgg.astype(float)
          imgg=(imgg-dd)/df
          imgg.astype(int)
  plt.imshow(imgg,cmap=plt.cm.Greys_r,vmin=0.5,vmax=1.5)
  plt.show()
  </code></pre>