# How to scale values for ColorFunction in SliceContourPlot3D?

Trying to help out in the question, Finite Elements 3D, I came across this behavior of SliceContourPlot3D:

op = -Laplacian[u[x, y, z], {x, y, z}] - 2;
uif = NDSolveValue[{op == 0, DirichletCondition[u[x, y, z] == 0, True},
u, {x, y, z} ∈ Ball[{0, 0, 0}]];

SliceContourPlot3D[
uif[x, y, z], "CenterPlanes", {x, y, z} ∈ MeshRegion@uif["ElementMesh"],
ColorFunction -> "Rainbow"]


The range of colors does not go all the way down to violet/indigo. I expected the range of colors to be something like this:

With[{sel = Positive[uif["Grid"].{0.3, -0.4, -1}]},
With[{pts = Pick[uif["Grid"], sel]},
Graphics3D[
GraphicsComplex[
pts,
{Point[Range@Length@pts,
VertexColors -> (ColorData["Rainbow"] /@ Rescale[Pick[uif["ValuesOnGrid"], sel]])
]}
]]
]]


Is this a bug in SliceContourPlot3D? (Perhaps it's due to extrapolation from sampling outside the domain?) Is there a way to get it to rescale the colors the way I expected?

I'm using V10.3.0, Mac OSX.

• Looks that SliceContourPlot3D is a function of Mathematica 10.3.0. To me it is not working. I'm using 10.0.0. Dec 20, 2015 at 19:54

It seems SliceContourPlot3D makes an initial sample, that is not quite right - i.e. outside of the region. Using

op = -Laplacian[u[x, y, z], {x, y, z}] - 2;
uif = NDSolveValue[{op == 0,
DirichletCondition[u[x, y, z] == 0, True]},
u, {x, y, z} \[Element] Ball[{0, 0, 0}],
"ExtrapolationHandler" -> {(Indeterminate &),
"WarningMessage" -> False}];

SliceContourPlot3D[
uif[x, y, z], "CenterPlanes", {x, y, z} \[Element]
MeshRegion@uif["ElementMesh"], ColorFunction -> "Rainbow"]


On a related note, I am wondering if for FEM this ExtrapolationHandler should be the default - what do you think?

• I almost always use this extrapolation handler, because in my uses of interpolation, extrapolation is usually inappropriate. Not sure if turning off the warning message by default is the best choice or not. Plotters suppress such warnings automatically, it seems. Sometimes, it might be good to be warned. Dec 20, 2015 at 22:13
mesh = BoundaryDiscretizeRegion[Ball[{0, 0, 0}]];
alpha = 0.;
op = -Laplacian[u[x, y, z], {x, y, z}] - 2
Subscript[\[CapitalGamma],
D] = {DirichletCondition[u[x, y, z] == 0, True]};
uif = NDSolveValue[{op == 0, Subscript[\[CapitalGamma], D]},
u, {x, y, z} \[Element] mesh]
sol2 = Plot[uif[x, 0, 0], {x, -1, 1}]
SliceContourPlot3D[
uif[x, y, z], "CenterCutSphere", {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
AxesLabel -> Automatic, ColorFunction -> "BrightBands",
PlotLegends -> Automatic]