# Plotting: 4D in 3D or 2D

I have the following function (for example):

$$f(x,y,z)=\frac{xz^2}{y}$$

Question 1: I'm wondering how to plot f versus x (continuos), y (continuos) and z (discrete) in 1 3D graph. Any code would help. I'm looking for something like this:

I know this:

Plot3D[x z^2/y, {x,1*^9,1*^11}, {y,1*^-6,100*^-6}]


where I set z to different values every time. I do not know how to put them all in one plot with transparent coloring.

Question 2: Is there any way to show a 4D plot into one 2D plot, by any chance? This is a trick that I usually do when I have 3D plots, e.g. f(a,b).

• Look up ContourPlot3D. – Szabolcs Sep 7 '17 at 20:37
• @Szabolcs Thanks but it does not provide multiple surfaces in the way I described. – Kyle Dean Sep 7 '17 at 20:43
• You might get some ideas from Four-variable carpet plots or from that article's references. – LouisB Sep 8 '17 at 3:26

Question 1:

 Plot3D[Table[(x^2 + y^2)^4  z^2, {z, 1, 26, 4}] // Evaluate,
{x, -1, 1}, {y, -1, 1}, PlotStyle -> Opacity[.2], Mesh -> False,
ClippingStyle -> None]


yields:

Plot3D[Table[x z^2/y, {z, 1, 26, 4}] // Evaluate, {x, 1, 100}, {y, 1,
100}, PlotStyle -> Opacity[.2], Mesh -> False,
ClippingStyle -> None,PlotPoints->50]


yields:

Updated to handle comment requests of showing how to plot label, dealing with scaling issues.

So my version of Mathematica (11.1 Mac Os X) got aggravated by the extreme difference in ranges and just showed grayscale. Fortunately it's easy to scale the arguments without affecting the display, and manually setting the labels.

I.e. instead of considering $x z^2/y$, define $x'=x/10^9$, $y'=y\times10^6$, and $z'=z\times 10^7$. This way: $x z^2 / y = 10 x' (z')^2/y'$. Same plot except now you're plotting over $x' \in \{1,100\}$, $y' \in \{1,100\}$, and taking $z \in \{1, 5 , 10, 50, 100\}$, and Mathematica's less grumpy. Only downside is manually setting tick labels.

Now to address the labeling of each surface, I show two options, one a plot-legend to the side using PlotLegends, the by showing the plot with Text objects manually written into a Graphics3D wrapper. The later is more annoying as these surfaces get very close to each other and so the text overwrites for the bottom surfaces. In any case here's a proof of concept at least -- you may want to adjust coordinates as you like, to try to separate out the bottom guys, or just go with the legend.

Show[Plot3D[
Table[10  x  z^2/y, {z, {1, 5 , 10, 50, 100}}] // Evaluate, {x, 1,
100}, {y, 1, 100}, PlotStyle -> Opacity[.2], Mesh -> False,
ClippingStyle -> None, AxesLabel -> {"x", "y", ""},
PlotRange -> {0, 20*100^2},
Ticks -> { Table[{x, ScientificForm[x*10.^9]}, {x, {1, 50, 100}}],
Table[{y, ScientificForm[y*10.^-6]}, {y, {1, 50, 100}}],
Table[{z, ScientificForm[z]}, {z, {1, 10.^5, 2 10.^5}}]},
PlotLabel -> "x \!$$\*SuperscriptBox[\(z$$, $$2$$]\)/y",
PlotLegends ->