1
$\begingroup$

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:

enter image description here

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).

enter image description here

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

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:

enter image description here

Your function, e.g.:

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:

enter image description here


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 -> 
   Table[TraditionalForm[  z == ScientificForm[zz]], {zz, 
     10.^-7 {1, 5 , 10, 50, 100}}]],
 Graphics3D[
  Table[Text[
    TraditionalForm[  z == ScientificForm[zz*10.^-7]], {100, 60, 
     50/3   zz^2 }], {zz, {1, 5 , 10, 50, 100}}]]]

yielding, e.g.

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. Can you apply your method on my own function too. I'm getting nonesense $\endgroup$ – Kyle Dean Sep 7 '17 at 20:55
  • $\begingroup$ Updated to describe your function, but I choose friendly ranges. Do you want me to try to make sense of your particular extreme values of x and y? $\endgroup$ – John Joseph M. Carrasco Sep 7 '17 at 20:56
  • $\begingroup$ Can you please kindly, show me how to put z values next to the corresponding surfaces like "z=12" (similar to the picture in the question). I also appreciate if you can fix axes and name them properly. Good job. I'm new to Mathematica :) $\endgroup$ – Kyle Dean Sep 7 '17 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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