title: Python - Fitting 2D rectangular data
body: <p>I am writing a program using python 2.7 and am having difficulting pinpointing the best way to interpolate/fit some rectangular data.</p>
  
  <p>I have a bunch of known data points of the format z=f(x,y) where x and y are evenly spaced on a grid.  My x points range from 0 to 100 in increments of 0.1.  My y points range from 0 to 100 in increments of 2. </p>
  
  <p>My issue in interpolating or fitting this data is the large spacing between my y data coordinates.  I am looking for the best way to fit this data so that I can evaluate the height Z for any (X,Y) coordinate pair.  I want the resulting surface to be as smooth as possible.  The conventional methods using griddata, or rectbivariatespline do no produce smooth surfaces - seemingly because the space between my y points is much greater than the space between my x points.</p>
  
  <p>One option I considered was to use polyfit (or something similar) to fit a polynomial to each slice (the Y vs Z curve at each X) then to interpolate these slices together to produce a smoother surface.  This seems like kind of a roundabout way of doing things.  Is that my best option?</p>
  
  <p><em>example of fitting a slice to a polynomial:</em>
  <img src="https://i.stack.imgur.com/mdhhD.png" alt="fitting data"></p>
  
  <p>If fit to a polynomial, each of my slices (Y vs Z at a fixed X) is roughly gaussian or bimodal.  They are fairly simple distributions.</p>
  
  <p>My goal is to be able to produce a smooth, closely fit surface for display in 3D or on a pcolor style chart.  I need to avoid swings past Zmax and Zmin.  I know this is an issue when using splines.</p>
  
  <p><em>my goal:</em></p>
  
  <p><img src="https://i.stack.imgur.com/xSKdI.png" alt="goal surface"></p>
  
  <p>Thank you for any help you can provide.  I will watch this thread carefully and respond quickly if you need any elaboration.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>From what I have read, it seems like what I am looking for is a <em>shape preserving</em> interpolation method in python for 2d data.  I need something along the lines of pchip for matlab, but for a surface.  I have looking through all the documentation and can't find anything shape preserving that will give me a smooth surface.</p>