title: Python: using X and Y values to draw a picture
body: <p>I have a series of methods that take an image 89x22 pixels (although the size, theoretically, is irrelevant) and fits a curve to each row of pixels to find the location of the most significant signal. At the end, I have a list of Y-values, one for each row of pixels, and a list of X-values, the location of the most significant peak for each row. </p>
  
  <p>I would like to test different types of curves to see which models the data better, and in order to do so, I would like to be able to print out a new image, also 89x22 pixels, with the location of the most significant peak marked with a single red pixel for each line. A have attached an input example and a (poorly drawn) example of what I expect a good output to look like:</p>
  
  <p><img src="https://i.stack.imgur.com/imiSR.png" alt="input image"> <img src="https://i.stack.imgur.com/hjc79.png" alt="output image"></p>
  
  <p>Any suggestions on which modules to start looking in? </p>
  
  <pre><code>class image :
  
      def importImage (self) :
          """Open an image and sort all pixel values into a list of lists"""
          from PIL import Image               #imports Image from PIL library
  
          im = Image.open("testTop.tif")      #open the file
          size = im.size                      #size object is a tuple with the pixel width and pixel height
          width = size[0]                     #defines width object as the image width in pixels
          height = size[1]                    #defines the height object as the image height in pixels
  
          allPixels = list(im.getdata())      #makes a list of all pixels values
          pixelList = [allPixels[width*i : width * (i+1)] for i in range(height)]     #takes mega-list and makes a list of lists by row
          return(pixelList)                   #returns list of lists
  
      def fitCurves (self) :
          """
          Iterate through a list of lists and fit a curve to each list of integers. 
          Append the position of the list and the location of the vertex to a growing list.
          """
          from scipy.optimize import curve_fit
          import numpy as np
          from matplotlib import pyplot as pp
          from scipy.misc import factorial
  
          image = self.importImage()
          xList = []
          yList = []
          position = 0
  
          for row in image :
              #Gaussian fit equations kindly provided by user mcwitt
              x = np.arange(len(row))
              ffunc = lambda x, a, x0, s: a*np.exp(-0.5*(x-x0)**2/s**2)   # define function to fit
              p, _ = curve_fit(ffunc, x, row, p0=[100,5,2])           # fit with initial guess a=100, x0=5, s=2
              x0 = p[1]
              yList.append(position)
              position = position + 1
              xList.append(x0)
          print(yList)
          print(xList)
  
  newImage = image()
  newImage.fitCurves()
  </code></pre>