This question already has an answer here:

Visualize Plot of a function of 3 Variables using color and contours

2 answers

I have a function

f[x_, y_, z_] := Exp[-x^2]*Exp[-z^2]

which traces out a tube along yy. Is there a way to plot this 4D function, where the plot color is the 4th dimension?

=================

=================

3 Answers

3

=================

I think what you’re after is ContourPlot3D. There are two ways to color the contours.

ColorFunction has a certain attractive automatic feature to it, but it doesn’t color as nicely as ContourStyle, especially if you are coloring the surfaces by the function value. ContourStyle produces smaller graphics and is faster, too.

cons = {0.2, 0.4, 0.6, 0.8};

ContourPlot3D[

Exp[-x^2]*Exp[-z^2], {x, -1, 1}, {y, -1, 1}, {z, -1, 1},

Mesh -> None,

Contours -> cons, ContourStyle -> Hue /@ cons]

ContourPlot3D[Exp[-x^2]*Exp[-z^2], {x, -1, 1}, {y, -1, 1}, {z, -1, 1},

Mesh -> None, MaxRecursion -> 3,

ColorFunction -> Function[{x, y, z, f}, Hue[f]]]

You can also diminish the Opacity of the contours; see the manual.

You can vary the color of the tube as it goes along – if you provide a list of the colours that it passes through to VertexColors:

Graphics3D[

{CapForm[“Round”],

Tube[

Accumulate[

RandomReal[{-3, 3}, {50, 3}]], .3,

VertexColors ->

Table[RGBColor[x, 1 – x, 0.5 – x/2], {x, 0, 1, 1/50}]]

},

Lighting -> “Neutral”,

Background -> Gray,

Boxed -> False]

Have I understood correctly? Look at this:

Edit: I forgot ColorFunctionScaling. Now it is ok.

RegionPlot3D[

x^2 + z^2 <= 1, {x, -2, 2}, {y, -12, 12}, {z, -2, 2}, Mesh -> None,

ColorFunctionScaling -> False,

ColorFunction ->

Function[{x, y, z}, ColorData[“Rainbow”][Exp[-x^2]*Exp[-z^2]]]]