2

I am trying to create a plot of a surface that is yellow above the xy-plane (z>0), but blue below (z<0). My first attempt was to use ColorFunction->Function[{x,y,z},If[z>0,Hue[0.2],Hue[0.6]], but this only gave me a solid yellow paraboloid. I also tried defining a custom ColorFunction scheme with cf=Piecewise[{{Yellow,0<#3<30},{Blue,-70<#3<0}}]&; and ColorFunction->cf to the same result. Finally, I tried the following based on another thread (Discrete coloring in Plots):

ParametricPlot3D[{x,y,x^2+y^2-5},{y,-3,3},{x,-3,3},PlotStyle->Opacity[.8],ColorFunction->(If[#3>0,Yellow,Blue]&),Mesh->False,BoundaryStyle->{Black,Thickness[.01]}]

Every time, I end up with this:

yellow paraboloid

Any help you can offer would be greatly appreciated.

  • 1
    Try ColorFunctionScaling -> False? and a large value for PlotPoints , e.g., PlotPoints -> 150. – kglr Jul 19 '14 at 01:40
  • Thank you! Do you know how to limit the artifacts near z=0 so that it is more of a discrete color change? PlotPoints->100 works, but it slows everything down.

    http://i.imgur.com/tFh63XY.jpg

    – WorfSonOfMogh Jul 19 '14 at 01:42
  • Worf, i don't know of any way to get rid of the jagged ring. A work-around is to "hide" it under a mesh at 0 using the combination of options MeshFunctions -> {#3 &}, Mesh -> {{0}}, MeshStyle -> Directive[Blue, Opacity[.8], Thickness[.01]]. ... Just learned myself the best way: Michael's approach using MeshShading :) – kglr Jul 19 '14 at 02:01

2 Answers2

7

I would use MeshShading, as shown in the documentation for ParametricPlot3D:

ParametricPlot3D[{x, y, x^2 + y^2 - 5}, {y, -3, 3}, {x, -3, 3}, 
 MeshShading -> {Directive[Opacity[.8], Blue], 
   Directive[Opacity[.8], Yellow]}, Mesh -> {{0}}, 
 MeshFunctions -> {#3 &}, BoundaryStyle -> {Black, Thickness[.01]}, 
 Lighting -> "Neutral"]

Mathematica graphics

Michael E2
  • 235,386
  • 17
  • 334
  • 747
0
  1. Use your cf as the setting for ColorFunction and add the option ColorFunctionScaling -> False.
  2. To get a sharp change from Blue to Yellow add the options Exclusions -> {x^2 + y^2 == 5} and ExclusionsStyle -> Blue.

ParametricPlot3D[{x, y, x^2 + y^2 - 5}, {y, -3, 3}, {x, -3, 3},
 PlotStyle -> Opacity[.8], Mesh -> None, BoundaryStyle -> {Black, Thickness[.01]},
 ColorFunction -> cf, ColorFunctionScaling -> False, 
 Exclusions -> {x^2 + y^2 == 5}, ExclusionsStyle -> Blue]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896