"""
Plotting 2D data
================

Often measured data is in 2D, but locations are not gridded.
Data can be vectoral, hence we want to plot direction and
amplitude of the vector. Following example use SimPEG's
analytic function (electric dipole) to generate data
at 2D plane.
"""
from SimPEG import EM, Utils
import numpy as np
import matplotlib.pyplot as plt


def run(plotIt=True):
    # Make un-gridded xyz points

    x = np.linspace(-50, 50, 30)
    x += np.random.randn(x.size)*0.1*x
    y = np.linspace(-50, 50, 30)
    y += np.random.randn(x.size)*0.1*y
    z = np.r_[50.]
    xyz = Utils.ndgrid(x, y, z)
    sig = 1.
    f = np.r_[1.]
    srcLoc = np.r_[0., 0., 0.]

    # Use analytic fuction to compute Ex, Ey, Ez
    Ex, Ey, Ez = EM.Analytics.E_from_ElectricDipoleWholeSpace(
        xyz, srcLoc, sig, f
    )

    if plotIt:
        plt.figure()
        ax1 = plt.subplot(121)
        ax2 = plt.subplot(122)
        # Plot Real Ex (scalar)
        cont1, ax1 = Utils.plot2Ddata(
            xyz, Ex.real, dataloc=True,
            ax=ax1, contourOpts={"cmap": "viridis"},
            ncontour=5)
        # Make it as (ndata,2) matrix
        E = np.c_[Ex, Ey]
        # Plot Real E (vector)
        cont2, ax2 = Utils.plot2Ddata(
            xyz, E.real, vec=True,
            ax=ax2, contourOpts={"cmap": "viridis"},
            ncontour=5)
        cb1 = plt.colorbar(
            cont1, ax=ax1, orientation="horizontal",
            format='%.1e'
        )
        cb1.ax.set_xticklabels(cb1.ax.get_xticklabels(), rotation=45)
        cb2 = plt.colorbar(
            cont2, ax=ax2, orientation="horizontal",
            format='%.1e'
        )
        cb2.ax.set_xticklabels(cb2.ax.get_xticklabels(), rotation=45)
        ax1.set_xlabel("x")
        ax1.set_ylabel("y")
        ax2.set_xlabel("x")
        ax2.set_ylabel("y")

        ax1.set_aspect('equal', adjustable='box')
        ax2.set_aspect('equal', adjustable='box')


if __name__ == '__main__':
    run()
    plt.show()

@@ -968,16 +968,24 @@
 nt1, ax1
+, cont1l
  = Utils
@@ -989,32 +989,32 @@
 ils.plot2Ddata(%0A
-
             xyz,
@@ -1104,32 +1104,133 @@
       ncontour=5
+, level=True,%0A            levelOpts=%7B'colors': 'k', 'linestyles': 'dashed', 'linewidths': 1%7D%0A        
 )%0A        # Make
@@ -1429,32 +1429,32 @@
 p%22: %22viridis%22%7D,%0A
-
             ncon
@@ -1459,16 +1459,25 @@
 ontour=5
+%0A        
 )%0A      

update example