title: Python convert large data arrays to grid for matplotlib
body: <p>i want to use a defined function to convert the input data to grid-arrays, which can be used by matplotlib. For an example with bigger data look at my <a href="https://dl.dropboxusercontent.com/u/59720953/griddata.zip" rel="nofollow">griddata.zip</a> file.
  The arrays look like e.g.: <code>x = [0,1.0,2.0], y = [0.0,10.0,20.0], z = [0.0, 20.0, 50.0]</code> meaning, that they have the same length, and z should be the plotted on the x-y-grid.:
  Basically, there were some efforts to answer this before. A possible solution was given by M4rtini:</p>
  
  <pre><code>from numpy import linspace, meshgrid
  import numpy as np
  from pprint import pprint
  from scipy.interpolate import griddata
  
  def grid(x, y, z, resX=100, resY=100):
      "Convert 3 column data to matplotlib grid"
      grid_x, grid_y = np.mgrid[min(x): max(x):1j * resX, min(y): max(y):1j * resY]
      Z = griddata(np.array(zip(x, y)), np.array(z), (grid_x, grid_y), method='nearest')
      return grid_x, grid_y, Z
  
  x =[0,1.0,2.0]
  y = [0.0,10.0,20.0]
  z = [0.0, 20.0, 50.0]
  
  X,Y,Z =  grid(x,y,z)
  
  from mpl_toolkits.mplot3d import Axes3D
  import matplotlib.pyplot as plt
  
  fig = plt.figure()
  ax = fig.gca(projection='3d')
  
  ax.plot_surface(X,Y,Z)
  plt.show()
  </code></pre>
  
  <p>The plot output should look like this for the large data file: <a href="https://dl.dropboxusercontent.com/u/59720953/figure.png" rel="nofollow">Image of Plot output</a></p>