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

I would like to plot a function of three variables, say for example:

$$f(x,y,z) = x^2+y^3+z^4$$

over $$[-1, +1]$$. I want my plot to use colors and maybe contours to make this visualization possible using a single plot. Any ideas? Example code would help a lot!

### EDIT

I would like to have the $$xy$$ axes shown and $$z$$ as a "dynamic" variable (with sliding bar) and the output as a flat, colored contour map.

• Check ContourPlot3D. – Szabolcs May 15 '13 at 23:37
• It doesn't really "make sense" even for a simple function ContourPlot3D[x + y + z, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}] – Squirtle May 15 '13 at 23:45
• ContourPlot3D[x + y + z, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> False, ColorFunction -> "Rainbow"]. It sounds like you're not sure what you want to draw on the screen. Try to think up a way to visualize the function, then ask about how to implement that. – Szabolcs May 15 '13 at 23:47
• Re your edit: Manipulate. – Szabolcs May 15 '13 at 23:48
• Even if this is your first time using the program, if you expect people to work on your problem, you should show them that at least you tried to solve it yourself. I gave you some pointers to the functions you need. Their documentation pages have many examples. Have you checked them? – Szabolcs May 16 '13 at 0:32

## 2 Answers

Manipulate[
ContourPlot[x^2 + y^3 + z^4, {x, -1, 1}, {y, -1, 1}, ColorFunction -> "DarkRainbow"]
,{z, -1, 1}] ### EDIT:

A few values in 3D plot:

Plot3D[Evaluate@Table[x^2 + y^3 + z^4, {z, {0, 0.8, 1}}], {x, -1, 1}, {y, -1, 1}, PlotStyle -> {Red, Green, Blue}] But I'd rather put a few contour plots next to each other. In general take a look at the Mathematica help, there are lots of examples. You'll also find more options, like ColorFunctionScaling

 With[{z = 0},
ContourPlot[x^2 + y^3 + z^4, {x, -1, 1}, {y, -1, 1},
ColorFunction -> "DarkRainbow",
PlotLegends -> BarLegend[Automatic]]
]

• One more thing! This is VERY cool.... however, this has to be put in a paper (for publication), so perhaps what I am looking for is for a short list of some values (z_1,z_2, ...z_n : say n=4), I want to plot f(x,y,z) (x and y vary as before, but superimpose SOME values of z). Using a "traditional Plot3D". Thank you and sorry for the modification on the question. In other words, "stack" various plots of the same function for a few different values of z. – Squirtle May 16 '13 at 0:20
• Thanks @jenson again! We should close this threat now, I found this very useful. I wish I could vote up twice! – Squirtle May 16 '13 at 1:59

As an alternative, you can also use Image3D to visualize 3-variable functions:

valueInterval = Through[{MinValue, MaxValue}[
{x^2 + y^3 + z^4, And @@ Thread[-1 <= {x, y, z} <= 1]}, {x, y, z}]];

Outer[
Function[{z, y, x}, If[x > 0 && y > 0 && z > 0, 0,
4 Mod[Rescale[x^2 + y^3 + z^4, valueInterval], 1/5]
]], Reverse@#, Reverse@#, #] &@
Range[-1, 1, .02] //
Image3D[#, ColorFunction -> "RainbowOpacity",
Boxed -> True, Axes -> True, AxesOrigin -> {1, 1, 1}/.02,
AxesLabel -> (ToBoxes[Style[#, 20]] & /@ {x, y, z})] & Or a 3D version DensityPlot:

Outer[
Function[{z, y, x}, If[x > 0 && y > 0 && z > 0, 0,
Rescale[x^2 + y^3 + z^4, valueInterval]^2.2
]], Reverse@#, Reverse@#, #] &@
Range[-1, 1, .02] //
Image3D[#, ColorFunction -> "RainbowOpacity",
Boxed -> True, Axes -> True,
AxesLabel -> (ToBoxes[Style[#, 20]] & /@ {x, y, z})] & 