title: numpy contour: TypeError: Input z must be a 2D array
body: <p>I have data in a list of lists format.</p>
  
  <p>It looks like this:</p>
  
  <pre><code>[(x_1, y_1, Z_1),...(x_i, y_j, z_k),...(x_p, y_q, z_r)]
  </code></pre>
  
  <p>For every x and y there is one z. Lengths of X, Y and Z are p, q and r(=p*q) respectively.</p>
  
  <p>I intend to plot a contour plot with X and Y as mesh and Z as the value to be plotted.</p>
  
  <p>I have following code (just representative):</p>
  
  <pre><code>import csv
  import sys
  import statistics
  import numpy as np
  from scipy.interpolate import UnivariateSpline
  from matplotlib import pyplot as plt
  ...........
  
  #format of data = [(x, y, z)......]
  
  #x, y, z are lists
  
  X = [X1,..........,Xp] #length, p 
  
  Y = [Y1,..........,Yq] #length, q
  
  Z = [Z1,..........,Zpq] #length, pq
  
  #np.mesh
  
  X1, Y1 = np.meshgrid(X, Y)
  
  plt.figure()
  CS = plt.contour(X1, Y1, Z)
  plt.clabel(CS, inline=1, fontsize=10)
  </code></pre>
  
  <p>I get following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/uname/PycharmProjects/waferZoning/contour.py", line 49, in &lt;module&gt;
      CS = plt.contour(X1, Y1, Z)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\pyplot.py", line 2766, in contour
      ret = ax.contour(*args, **kwargs)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\__init__.py", line 1811, in inner
      return func(ax, *args, **kwargs)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\axes\_axes.py", line 5640, in contour
      return mcontour.QuadContourSet(self, *args, **kwargs)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\contour.py", line 1428, in __init__
      ContourSet.__init__(self, ax, *args, **kwargs)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\contour.py", line 873, in __init__
      self._process_args(*args, **kwargs)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\contour.py", line 1445, in _process_args
      x, y, z = self._contour_args(args, kwargs)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\contour.py", line 1532, in _contour_args
      x, y, z = self._check_xyz(args[:3], kwargs)
    File "C:\Users\uname\AppData\Local\Programs\Python\Python35\lib\site-packages\matplotlib\contour.py", line 1566, in _check_xyz
      raise TypeError("Input z must be a 2D array.")
  TypeError: Input z must be a 2D array.
  </code></pre>
  
  <p>I understand what the error is, but I am not able to rectify it.</p>
  
  <p>I can't give a MWE but I guess I have made my problem quite clear. </p>
  
  <p><a href="https://www.dropbox.com/s/33jmfcjzikl4w5g/contour_synthetic.txt?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/33jmfcjzikl4w5g/contour_synthetic.txt?dl=0</a></p>