Graphics`PlotOnGrid`

This package provides routines to plot functions with two variables on a grid or a specified curve to a Graphics3D object using the normal Plot function.In contrast to a Plot3D call,these routines will adapt rather smoothly to discontinuities and singularities of the function to be plotted thus resulting in a far more accurate plot.

Syntax.

This loads the package.

Needs["Graphics`PlotOnGrid`"];

With PlotOnCurve, you can sample your two-dimensional function on a given curve

f[x_, y_] := Exp[-((x^2) + (y^2))];

PlotOnCurve[f[x, y], {x, y}, {t, t}, {t, -2, 2}, 
        Axes -> True];

This result can be combined with a conventional surface plot:

Show[%, 
        Plot3D[f[x, y], {x, -2, 2}, {y, -2, 
            2}, 
Mesh -> False, 
          DisplayFunction -> Identity]];

PlotOnGrid can be used to plot a given function to high accuracy on a grid. It accepts all valid options for Graphics3D objects.

PlotOnGrid[f[x, y], {x, -2, 2}, {y, -2, 2}, 
        Shading -> False, Boxed -> False];

Options for PlotOnGrid.

With the option Shading->True, a three-dimensional surface plot and the grid plot can automatically be combined. The option MeshSeparation->0.005 is used to raise the grid lines a little bit above the surface mesh.

PlotOnGrid[f[x, y], {x, -2, 2}, {y, -2, 2}, 
        MeshSeparation -> 0.005, 
        MeshFunction -> Plot3D];

If available, PlotOnGrid will use a Delaunay triangulation for composing the shaded mesh.

Options[PlotOnGrid, MeshFunction]

PlotOnGrid[f[x, y], {x, -2, 2}, {y, -2, 2}, 
        MeshSeparation -> 0.005];

The following statement uses the Discontinuities option to add additional contour lines.

p = 
        PlotOnGrid[
          f[x, y], {x, -2, 2}, {y, -2, 
            2}, 
Boxed -> False, Shading -> True, 
          PlotPoints -> 10, 
          MeshFineness -> 
            3, 
Discontinuities -> {PlotOnCurve[
                f[x, y], {x, y}, 0.54 {Sin[t], Cos[t]}, {t, 0, 2  π}, 
                DisplayFunction -> Identity], 
              PlotOnCurve[f[x, y], {x, y}, 
                0.83 {Sin[t], Cos[t]}, {t, 0, 2  π}, 
                DisplayFunction -> Identity], 
              PlotOnCurve[f[x, y], {x, y}, 
                1.18 {Sin[t], Cos[t]}, {t, 0, 2  π}, 
                DisplayFunction -> Identity]}];

PlotOnGrid is especially useful for functions with sudden changes along one axis. Whereas a regular surface plot cannot locate the branch cut of the square root function accurately, PlotOnGrid can resolve it:

f[x_, y_] := Im[Sqrt[x + I y]];

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}];

PlotOnGrid[
        Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}];

The following example uses the the Discontinuities option for clearly identifying the location of the branch cut and, in addition, marks it with a red line:

bc1 = 
        PlotOnCurve[f[x, y], {x, y}, {t, -0.01}, {t, -2, 0}, 
          PlotStyle -> {Thickness[0.01], RGBColor[1, 0, 0]}, 
          DisplayFunction -> Identity];
bc2 = 
        PlotOnCurve[f[x, y], {x, y}, {t, 0.01}, {t, -2, 0}, 
          PlotStyle -> {Thickness[0.01], RGBColor[1, 0, 0]}, 
          DisplayFunction -> Identity];
s = 
        PlotOnGrid[Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}, 
          Shading -> True, Mesh -> False, 
          MeshSeparation -> 0.005, Discontinuities -> {bc1, bc2}, 
          DisplayFunction -> Identity];
Show[{s, bc1, bc2}, 
        DisplayFunction -> $DisplayFunction];

The only method to prevent grid lines from being hidden by the surface mesh is by fine-tuning the MeshSeparation option. This sometimes does not produce satisfactory results.
If discontinuities or phase boundaries of a function are known, you might be better of using an approach as implemented in the package Graphics`phasePlot3D` (see http://library.wolfram.com/infocenter/MathSource/758/).