title: values at coordinates to image
body: <p>I have a text file with measurement data which looks like this.</p>
  
  <pre><code>x   y   z
  1   3   -2
  2   1   -3
  3   1   1
  2   2   3
  1   2   2
  2   3   0
  </code></pre>
  
  <p>This would imply the following measurement (on an x,y grid)</p>
  
  <pre><code>-2   0
   2   3
      -3   1
  </code></pre>
  
  <p>I want to create an image from these values where no measurement would mean that the image is transparent. If possible I would like to map the z values (from for example -9.4 to +3.2) to a colormap such as colormap.jet</p>
  
  <p>I've tried to do this using the Python Image Library and putpixel but this is very slow and I'm sure there must be a better way of doing this.</p>
  
  <p>My current code:
      basePath = os.path.dirname(os.path.realpath(<strong>file</strong>)) # defines the directory where the current file resides
  srcFiles = glob.glob('*.pts')</p>
  
  <p>for fileName in srcFiles:</p>
  
  <pre><code>data = pd.read_csv(os.path.join(basePath, fileName), names=['x', 'y', 'z'], delim_whitespace=True)
  
  print fileName
  maxX = data.x.max()
  minX = data.x.min()
  maxY = data.y.max()
  minY = data.y.min()
  minZ = data.z.min()
  maxZ = data.z.max()
  
  width = maxX-minX
  height = maxY-minY
  
  img = Image.new('L', (int(width), int(height)))
  
  
  for x in range(int(width)):
      for y in range(int(height)):
          value = data[(data['x'] == (minX+x)) &amp; (data['y'] == (minY+y))]['z']
          if len(value) == 0:
              value = 99.;
  
          img.putpixel((x,y),int(value))
  
  img.save('test.png')
  </code></pre>