title: Compromise between scipy.interpolate.Rbf and scipy.interpolate.griddata?
body: <p>I need to generate a 2D density map given some unstructured <code>(x, y)</code> coordinates, and a <code>z</code> value which acts as the weight assigned to each point.</p>
  
  <p>I can interpolate the values into a grid (see code below) using either <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.Rbf.html" rel="noreferrer">scipy.interpolate.Rbf</a> or <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html" rel="noreferrer">scipy.interpolate.griddata</a>. The first one is very accurate but <em>very</em> slow, while the second one is <em>a lot</em> faster but noticeably less accurate.</p>
  
  <p>See image below where <code>Rfb</code> is to the left and <code>griddata</code> to the right:</p>
  
  <p><a href="https://i.stack.imgur.com/2KCvh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2KCvh.png" alt="enter image description here"></a></p>
  
  <p>Is there some way to compromise between these two functions? Something that will produce a result more similar to the <code>Rfb</code> function but with a speed more similar to that of the <code>griddata</code> function?</p>
  
  <pre><code># Data
  N = 1000
  x, y, z = np.random.uniform(0.0005, 0.03, N),\
      np.random.uniform(6., 10., N), np.random.uniform(1., 10., N)
  xmin, xmax, ymin, ymax = min(x), max(x), min(y), max(y)
  
  # Set up a regular grid of interpolation points
  xi, yi = np.linspace(xmin, xmax, 200), np.linspace(ymin, ymax, 200)
  xi, yi = np.meshgrid(xi, yi)
  # Normalize data and grid.
  x_new, xi_new = (x - xmin) / (xmax - xmin), (xi - xmin) / (xmax - xmin)
  y_new, yi_new = (y - ymin) / (ymax - ymin), (yi - ymin) / (ymax - ymin)
  
  # Interpolate new data with Rbf.    
  s = time.clock()
  rbf = scipy.interpolate.Rbf(x_new, y_new, z, function='linear')
  zi = rbf(xi_new, yi_new)
  print(time.clock() - s)
  # Plot density map.
  ax1 = plt.subplot(121)
  plt.pcolormesh(xi, yi, zi, cmap=plt.get_cmap('GnBu_r'), zorder=2)
  plt.contour(xi, yi, zi, 2, colors='#551a8b', linewidths=0.5, zorder=3)
  
  # Interpolate new data with griddata.    
  s = time.clock()
  # Python 2.7
  vals = zip(*[x_new, y_new])
  # Python 3.6
  # vals = np.array([x_new, y_new]).T
  zi = scipy.interpolate.griddata(vals, z, (xi_new, yi_new), method='linear')
  print(time.clock() - s)
  # Plot density map.
  ax2 = plt.subplot(122)
  plt.imshow(
      zi, extent=(xmin, xmax, ymin, ymax), origin='lower',
      cmap=plt.get_cmap('GnBu_r'))
  plt.contour(xi, yi, zi, 2, colors='#551a8b', linewidths=0.5, zorder=3)
  
  plt.show()
  </code></pre>