title: How to produce MATLAB plot (interpolation) in Matplotlib (Numpy)?
body: <p>I am trying to follow a MATLAB example of meshgrid + interpolation. The example code is found <a href="http://www.mathworks.com/help/matlab/visualize/representing-a-matrix-as-a-surface.html" rel="nofollow noreferrer">HERE</a>. On that site, I am going through the following example: <strong>Example – Displaying Nonuniform Data on a Surface</strong>.</p>
  
  <p>Now, I would like to produce a similar plot in Python (Numpy + Matplotlib) to what is shown there in MATLAB. This is the plot that MATLAB produces:
  <img src="https://i.stack.imgur.com/SHuC1.png" alt="enter image description here"></p>
  
  <p>I am having trouble with doing this in Python. Here is my code and my output in Python 2.7:</p>
  
  <pre><code>from matplotlib.mlab import griddata
  import matplotlib.pyplot as plt
  from matplotlib import cm
  import numpy as np
  from mpl_toolkits.mplot3d import Axes3D
  
  x = np.random.rand(200)*16 - 8
  y = np.random.rand(200)*16 - 8
  r = np.sqrt(x**2 + y**2)
  z = np.sin(r)/r
  
  xi = np.linspace(min(x),max(x), 100)
  yi = np.linspace(min(y),max(y), 200)
  
  X,Y = np.meshgrid(xi,yi)
  
  Z = griddata(x, y, z, X, Y, interp='linear')
  
  fig = plt.figure()
  ax = fig.gca(projection='3d')
  surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,cmap=cm.jet)
  </code></pre>
  
  <p>Here is the result of my attempt at doing this with matplotlib and NumPy.<img src="https://i.stack.imgur.com/ylb27.png" alt="My attempt in Numpy+Python">.</p>
  
  <p>Could someone please help me recreate the MATLAB plot in matplotlib, as either a mesh or a surface plot?</p>