Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I have a function

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

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

share|improve this question

marked as duplicate by J. M. Jun 8 '13 at 17:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I should have checked earlier: Duplicate: 1) and a couple of related ones: 2), 3) –  Michael E2 Jun 8 '13 at 17:37
1  
@MichaelE2 those weren't very tube-y, though, which I thought was the intention behind the Q. –  cormullion Jun 8 '13 at 19:17
    
@cormullion I think they are very tube-y but not Tube-y, since circular cylinders are tubes. I was confused at first whether "tube" meant Tube[..], but later I realized the contours were cylinders whose axis was the y-axis, just as in the Q. (Frankly, f does not trace out tubes and "the 4th dimension" is unclear. The function is not a parametrization, and "the 4th dimension" makes sense to me only if the Q is referring to the graph of f, which is a 3D hypersurface in R^4. I think one has to guess at the meaning of the Q as it is stated.) –  Michael E2 Jun 9 '13 at 2:52
add comment

3 Answers 3

up vote 3 down vote accepted

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]

ContourStyle

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]]]

ColorFunction

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

share|improve this answer
add comment

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]

its quicker by tube

share|improve this answer
add comment

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]]]]

enter image description here

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.