import numpy as np
from scipy.interpolate import LinearNDInterpolator
import matplotlib.pyplot as plt

def plot2Ddata(xyz, data, nx=100, ny=100, ax=None, mask=None, level=None, figname=None, ncontour=10, dataloc=False, contourOpts={}, clim=None):
    """
        TODOs:

            Write explanation for parameters

    """
    if ax is None:
        fig = plt.figure()
        ax = plt.subplot(111)

    xmin, xmax = xyz[:,0].min(), xyz[:,0].max()
    ymin, ymax = xyz[:,1].min(), xyz[:,1].max()
    x = np.linspace(xmin, xmax, nx)
    y = np.linspace(ymin, ymax, ny)
    X, Y = np.meshgrid(x, y)
    F = LinearNDInterpolator(xyz[:,:2], data)
    xy = np.c_[X.flatten(), Y.flatten()]
    DATA = F(xy)
    DATA = DATA.reshape(X.shape)
    cont = ax.contourf(X, Y, DATA, ncontour, **contourOpts)
    if level is not None:
        CS = ax.contour(X, Y, DATA, level, colors="k", linewidths=2)
#         plt.clabel(CS, inline=1, fmt="%.1e")
    if dataloc:
        ax.plot(xyz[:,0], xyz[:,1], 'k.', ms=1)
    plt.gca().set_aspect('equal', adjustable='box')
    if figname:
        plt.axis("off")
        fig.savefig(figname, dpi=200)
    if level is  None:
        return F, cont, ax
    else:
        return F, cont, ax, CS

@@ -121,16 +121,26 @@
 z, data,
+ vec=None,
  nx=100,
@@ -610,99 +610,558 @@
     
-F = LinearNDInterpolator(xyz%5B:,:2%5D, data)%0A    xy = np.c_%5BX.flatten(), Y.flatten()%5D%0A
+xy = np.c_%5BX.flatten(), Y.flatten()%5D%0A    if vec is None:%0A        F = LinearNDInterpolator(xyz%5B:,:2%5D, data)%0A        DATA = F(xy)%0A        DATA = DATA.reshape(X.shape)%0A        cont = ax.contourf(X, Y, DATA, ncontour, **contourOpts)%0A        if level is not None:%0A            CS = ax.contour(X, Y, DATA, level, colors=%22k%22, linewidths=2)%0A%0A    else:%0A        # Assume size of data is (N,2)%0A        datax = data%5B:,0%5D%0A        datay = data%5B:,1%5D%0A        Fx = LinearNDInterpolator(xyz%5B:,:2%5D, datax)%0A        Fy = LinearNDInterpolator(xyz%5B:,:2%5D, datay)%0A    
     DATA
  = F
@@ -1160,25 +1160,31 @@
 DATA
+x
  = F
+x
 (xy)%0A
+    
     DATA
  = D
@@ -1183,33 +1183,160 @@
 DATA
+y
  = 
-DATA.reshape(X.shape)%0A
+Fy(xy)%0A        DATA = np.sqrt(DATAx**2+DATAy**2).reshape(X.shape)%0A        DATAx = DATAx.reshape(X.shape)%0A        DATAy = DATAy.reshape(X.shape)%0A    
     
@@ -1387,24 +1387,81 @@
 ontourOpts)%0A
+        ax.streamplot(X, Y, DATAx, DATAy, color=%22w%22)%0A    
     if level
@@ -1466,32 +1466,36 @@
 el is not None:%0A
+    
         CS = ax.
@@ -1547,16 +1547,17 @@
 dths=2)%0A
+%0A
 #       
@@ -1819,33 +1819,36 @@
 %0A        return 
-F
+True
 , cont, ax%0A    e
@@ -1867,17 +1867,20 @@
  return 
-F
+True
 , cont, 

Fix plotting utils.