title: Spatial interpolation of discrete points onto x/y coordinate mesh grid in Python
body: <p>I'm still very new to programming and trying to create a contour plot of alkalinity across Hawaii using Cartopy. I will need to interpolate the point values called MODIFIED_TA against an x-y mesh grid but have not been able to figure out how to do this. The code I'm using is:</p>
  <pre><code>import cartopy.feature as cfeature
  import matplotlib.pyplot as plt
  import matplotlib.ticker as mticker
  import cartopy.crs as ccrs
  import cartopy.mpl.ticker as cticker
  import statistics
  from scipy.interpolate import UnivariateSpline
  import numpy as np
  from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
  import warnings
  
  warnings.filterwarnings(&quot;ignore&quot;) # ignoring the warning prompts.
  
  %matplotlib inline
  
  fig = plt.figure(figsize=(15,15))
  
  ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=-170))
  
  landgreen = cfeature.NaturalEarthFeature('physical', 'land', '110m', 
                                          edgecolor='face', facecolor='green')
  
  
  oceanaqua = cfeature.NaturalEarthFeature('physical', 'ocean', '110m', 
                                         edgecolor='face', facecolor='aqua')
  
  
  ax.set_extent([-151.5, -162, 18, 24], ccrs.PlateCarree())
  ax.set_title('TOTAL ALKALINITY')
  ax.add_feature(landgreen)
  ax.add_feature(cfeature.OCEAN, color = 'k')
  ax.gridlines(draw_labels=True)
  
  
  lon_formatter = cticker.LongitudeFormatter()
  lat_formatter = cticker.LatitudeFormatter()
  ax.xaxis.set_major_formatter(lon_formatter)
  ax.yaxis.set_major_formatter(lat_formatter)
  ax.grid(linewidth=2, color='black', alpha=0.5, linestyle='--')
  
  
  lons = all_data.LONGITUDE[:]
  lats = all_data.LATITUDE[:]
  alk = all_data.MODIFIED_TA[:]
  x1,y1 = np.meshgrid(lons,lats)
  z1,z2 = np.meshgrid(all_data.MODIFIED_TA,all_data.MODIFIED_TA)
  
  
  plt.tricontourf(lons,lats,alk, transform=ccrs.PlateCarree(), cmap=cm.gist_rainbow)
  plt.colorbar(shrink=0.5)
  plt.title('$A_{T}$ VALUES', color = 'k', fontname='Times New Roman',size = 23)
  
  plt.plot()
  </code></pre>
  <p>The result is nothing like what I was hoping for and again, I'm not sure how to interpolate this value so that it comes out as a smooth gradient across the x/y coordinate grid. Any help would be greatly appreciated!</p>
  <p><a href="https://i.stack.imgur.com/PhzkE.png" rel="nofollow noreferrer">See output here</a></p>