Skip to main content
added 478 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

You probably want

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3 &}, 
 Mesh -> {{0}}, MeshStyle -> {Directive[Thick, Green]}, 
 MeshShading -> {Red, Blue}, PlotRange -> All]

enter image description here

Alternatively,

Plot3D[Evaluate[ConditionalExpression[f[x, y], #] & /@ {f[x, y] <= 0, 
    f[x, y] > 0}], {x, -2, 2}, {y, -2, 2}, PlotStyle -> {Red, Blue}, 
 Mesh -> None, BoundaryStyle -> {1 -> Directive[Thick, Green], 2 -> None}]

enter image description here

Compare with what you get with ColorFunction (note the absence of Green line and the blending of Red and Blue at the boundary):

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> MyColorFunc, 
 PlotRange -> All, ColorFunctionScaling -> False]

enter image description here

Update: We can eliminate the blending using Exclusions -> {f[x,y] == 0} and use the option ExclusionsStyle to color the boundary between the two pieces:

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, 
 Exclusions -> {f[x, y] == 0}, 
 ExclusionsStyle -> Directive[Thick, Green], 
 ColorFunction -> MyColorFunc, PlotRange -> All, 
 ColorFunctionScaling -> False]

enter image description here

You probably want

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3 &}, 
 Mesh -> {{0}}, MeshStyle -> {Directive[Thick, Green]}, 
 MeshShading -> {Red, Blue}, PlotRange -> All]

enter image description here

Alternatively,

Plot3D[Evaluate[ConditionalExpression[f[x, y], #] & /@ {f[x, y] <= 0, 
    f[x, y] > 0}], {x, -2, 2}, {y, -2, 2}, PlotStyle -> {Red, Blue}, 
 Mesh -> None, BoundaryStyle -> {1 -> Directive[Thick, Green], 2 -> None}]

enter image description here

Compare with what you get with ColorFunction (note the absence of Green line and the blending of Red and Blue at the boundary):

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> MyColorFunc, 
 PlotRange -> All, ColorFunctionScaling -> False]

enter image description here

You probably want

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3 &}, 
 Mesh -> {{0}}, MeshStyle -> {Directive[Thick, Green]}, 
 MeshShading -> {Red, Blue}, PlotRange -> All]

enter image description here

Alternatively,

Plot3D[Evaluate[ConditionalExpression[f[x, y], #] & /@ {f[x, y] <= 0, 
    f[x, y] > 0}], {x, -2, 2}, {y, -2, 2}, PlotStyle -> {Red, Blue}, 
 Mesh -> None, BoundaryStyle -> {1 -> Directive[Thick, Green], 2 -> None}]

enter image description here

Compare with what you get with ColorFunction (note the absence of Green line and the blending of Red and Blue at the boundary):

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> MyColorFunc, 
 PlotRange -> All, ColorFunctionScaling -> False]

enter image description here

Update: We can eliminate the blending using Exclusions -> {f[x,y] == 0} and use the option ExclusionsStyle to color the boundary between the two pieces:

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, 
 Exclusions -> {f[x, y] == 0}, 
 ExclusionsStyle -> Directive[Thick, Green], 
 ColorFunction -> MyColorFunc, PlotRange -> All, 
 ColorFunctionScaling -> False]

enter image description here

added 279 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

You probably want

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3 &}, 
 Mesh -> {{0}}, MeshStyle -> {Directive[Thick, Green]}, 
 MeshShading -> {Red, Blue}, PlotRange -> All]

enter image description here

Alternatively,

Plot3D[Evaluate[ConditionalExpression[f[x, y], #] & /@ {f[x, y] <= 0, 
    f[x, y] > 0}], {x, -2, 2}, {y, -2, 2}, PlotStyle -> {Red, Blue}, 
 Mesh -> None, BoundaryStyle -> {1 -> Directive[Thick, Green], 2 -> None}]

enter image description here

Compare with what you get with ColorFunction (note the absence of Green line and the blending of Red and Blue at the boundary):

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> MyColorFunc, 
 PlotRange -> All, ColorFunctionScaling -> False]

enter image description here

You probably want

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3 &}, 
 Mesh -> {{0}}, MeshStyle -> {Directive[Thick, Green]}, 
 MeshShading -> {Red, Blue}, PlotRange -> All]

enter image description here

Compare with what you get with ColorFunction (note the absence of Green line and the blending of Red and Blue at the boundary):

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> MyColorFunc, 
 PlotRange -> All, ColorFunctionScaling -> False]

enter image description here

You probably want

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3 &}, 
 Mesh -> {{0}}, MeshStyle -> {Directive[Thick, Green]}, 
 MeshShading -> {Red, Blue}, PlotRange -> All]

enter image description here

Alternatively,

Plot3D[Evaluate[ConditionalExpression[f[x, y], #] & /@ {f[x, y] <= 0, 
    f[x, y] > 0}], {x, -2, 2}, {y, -2, 2}, PlotStyle -> {Red, Blue}, 
 Mesh -> None, BoundaryStyle -> {1 -> Directive[Thick, Green], 2 -> None}]

enter image description here

Compare with what you get with ColorFunction (note the absence of Green line and the blending of Red and Blue at the boundary):

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> MyColorFunc, 
 PlotRange -> All, ColorFunctionScaling -> False]

enter image description here

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

You probably want

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, MeshFunctions -> {#3 &}, 
 Mesh -> {{0}}, MeshStyle -> {Directive[Thick, Green]}, 
 MeshShading -> {Red, Blue}, PlotRange -> All]

enter image description here

Compare with what you get with ColorFunction (note the absence of Green line and the blending of Red and Blue at the boundary):

Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, ColorFunction -> MyColorFunc, 
 PlotRange -> All, ColorFunctionScaling -> False]

enter image description here