title: Matplotlib contour from xyz data: griddata invalid index
body: <p>I'm trying to do a contour plot using matplotlib of a file with the following format:</p>
  
  <p>x1 y1 z1</p>
  
  <p>x2 y2 z2</p>
  
  <p>etc</p>
  
  <p>I can load it with numpy.loadtxt to get the vectors. So far, no trouble.</p>
  
  <p>I read this to learn how to plot, and can reproduce it by copy paste, so i'm sure nothin is wrong with my installation:</p>
  
  <p><a href="http://matplotlib.org/examples/pylab_examples/griddata_demo.html" rel="noreferrer">http://matplotlib.org/examples/pylab_examples/griddata_demo.html</a></p>
  
  <p>I understand I have to input x and y as vector and z as an array ,which can be done with griddata. This is also what i find on this site.</p>
  
  <p>The documentation says:</p>
  
  <blockquote>
    <p>zi = griddata(x,y,z,xi,yi) fits a surface of the form z = f*(*x, y) to the data in the (usually) nonuniformly spaced vectors (x, y, z). griddata() interpolates this surface at the points specified by (xi, yi) to produce zi. xi and yi must describe a regular grid, can be either 1D or 2D, but must be monotonically increasing.</p>
  </blockquote>
  
  <p>For the sake of the example, I have written this code:</p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.mlab as ml
  
  x=np.linspace(1.,10.,20)
  y=np.linspace(1.,10.,20)
  z=np.linspace(1.,2.,20)
  
  xi=np.linspace(1.,10.,10)
  yi=np.linspace(1.,10.,10)
  
  zi = ml.griddata(x,y,z,xi,yi)
  </code></pre>
  
  <p>However, I get the following error when it comes to the griddata:
  IndexError: invalid index</p>
  
  <p>So, I tried to modify a bit the exemple of the doc like following:</p>
  
  <pre class="lang-py prettyprint-override"><code>from matplotlib.mlab import griddata
  import matplotlib.pyplot as plt
  import numpy as np
  x = np.linspace(-2.1,2.1,300)
  y = np.linspace(-2.1,2.1,300)
  z = x*np.exp(-x**2-y**2)
  # define grid.
  xi = np.linspace(-2.1,2.1,100)
  yi = np.linspace(-2.1,2.1,200)
  # grid the data.
  zi = griddata(x,y,z,xi,yi,interp='linear')
  </code></pre>
  
  <p>And I get the same error. I don't understand what's going wrong.</p>
  
  <p>Thanks for your help.</p>