0
$\begingroup$

Through code:

f[{x_, y_, z_}] = x^4 + y^4 + z^4;

r[t_] = {1/3 + 1/3 Cos[t] - 1/Sqrt[3] Sin[t],
         1/3 + 1/3 Cos[t] + 1/Sqrt[3] Sin[t],
         1/3 - 2/3 Cos[t]};
{min, max} = {0, 2 Pi};

ParametricPlot3D[
 r[t],
 {t, min, max},
 ColorFunction -> Function[t, 
   ColorData["Rainbow"][f[r[t]]]],
 AxesLabel -> {x, y, z},
 BoxRatios -> {1, 1, 1},
 PlotLegends -> BarLegend[{"Rainbow",
    {MinValue[{f[r[t]], min <= t <= max}, t],
     MaxValue[{f[r[t]], min <= t <= max}, t]}}]]

I get:

enter image description here

which it is certainly not what you want, because through this other code:

f[x_, y_, z_] = x^4 + y^4 + z^4;

A = ImplicitRegion[x^2 + y^2 + z^2 <= 1 && x + y + z <= 1, {x, y, z}];

SliceDensityPlot3D[
 f[x, y, z],
 BoundaryDiscretizeRegion[A],
 {x, y, z} \[Element] DiscretizeRegion[A],
 ColorFunction -> "Rainbow",
 AxesLabel -> Automatic,
 PlotLegends -> Automatic]

I get:

enter image description here

where the colors are very clear that it must be expected on the circumference above.

Where am I wrong?

$\endgroup$
  • $\begingroup$ Which minimum should be colored? Minimum t, min x, y, z, min length to point p/origin? (And try: ColorFunctionScaling -> False) $\endgroup$ – Julien Kluge Jan 25 '17 at 22:38
  • $\begingroup$ I tried but nothing changes. Above I have added details. Thank you. $\endgroup$ – TeM Jan 25 '17 at 22:50
  • $\begingroup$ Btw, note that your definition of functions should use SetDelayed if you define variables as patterns: f[x_,y_,z_]:=... $\endgroup$ – Felix Jan 26 '17 at 0:27
3
$\begingroup$

By default, color data is scaled such that it uses the entire range of the applied color function. To avoid this, set ColorFunctionScaling->False. Furthermore, ColorFunction, according to the documentation, should be a function of x,y,z,u (where u is t in your code). So here is the full call:

ParametricPlot3D[r[t], {t, min, max}, 
 ColorFunction -> 
  Function[{x, y, z, t}, ColorData["Rainbow"][f[r[t]]]],
 ColorFunctionScaling -> False, AxesLabel -> {x, y, z}, 
 BoxRatios -> {1, 1, 1}, 
 PlotLegends -> 
  BarLegend[{"Rainbow", {MinValue[{f[r[t]], min <= t <= max}, t], 
     MaxValue[{f[r[t]], min <= t <= max}, t]}}]]

enter image description here

$\endgroup$
  • $\begingroup$ @Manu: see updated code $\endgroup$ – Felix Jan 26 '17 at 0:24

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.