4
$\begingroup$

Writing:

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

r[u_] = {1/2 + 1/2 Cosh[u],
         Sqrt[2]/2 Sinh[u],
         1/2 - 1/2 Cosh[u]};
{min, max} = {-ArcSinh[2 Sqrt[2]], ArcSinh[2 Sqrt[2]]};

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

I get:

enter image description here

And I do not understand why in this case the color scale is so badly distributed. Is there a way to make it easier to read?

$\endgroup$
  • $\begingroup$ You could try rescaling the values you pass to ColorData: fmax=NMaxValue[{f[r[u]], min <= u <= max}, u]; then include ColorFunction -> Function[{x, y, z, u}, ColorData["Rainbow"][f[r[u]]/fmax]] $\endgroup$ – KraZug Jan 3 at 16:31
  • $\begingroup$ Thanks for the intervention, but unfortunately the problem persists. $\endgroup$ – TeM Jan 3 at 16:41
  • 1
    $\begingroup$ What exactly do you want? Your function $f$ is fairly flat over most of your range, then with a large increase towards the end of your range. $\endgroup$ – KraZug Jan 3 at 16:57
  • $\begingroup$ I would have liked to dilate the color scale to make it legible. In short, everything is red, I would not understand anything from a graph like that. $\endgroup$ – TeM Jan 3 at 17:29
4
$\begingroup$

Perhaps this is what you want?:

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

r[u_] = {1/2 + 1/2 Cosh[u], Sqrt[2]/2 Sinh[u], 1/2 - 1/2 Cosh[u]};
{min, max} = {-ArcSinh[2 Sqrt[2]], ArcSinh[2 Sqrt[2]]};
{fmin, fmax} = {NMinValue[{f[r[u]], min <= u <= max}, u], 
   NMaxValue[{f[r[u]], min <= u <= max}, u]};

Legended[
 ParametricPlot3D[r[u], {u, min, max}, BoxRatios -> {1, 1, 1}, 
  ColorFunction -> 
   Function[{x, y, z, u}, ColorData[{"Rainbow", {fmin, fmax}}][f[r[u]]]],
  ColorFunctionScaling -> False,
  AxesLabel -> {x, y, z}], BarLegend[{"Rainbow", {fmin, fmax}}]]

enter image description here

You need to manually rescale the ColorFunction input, if you use ColorFunctionScaling -> False, but that messes up BarLegend. Here is an alternative to Legended, using PlotLegends with an undocumented option to BarLegend:

ParametricPlot3D[r[u], {u, min, max}, BoxRatios -> {1, 1, 1}, 
 ColorFunction -> 
  Function[{x, y, z, u}, ColorData[{"Rainbow", {fmin, fmax}}][f[r[u]]]],
 ColorFunctionScaling -> False,
 AxesLabel -> {x, y, z}, 
 PlotLegends -> BarLegend[{"Rainbow", {fmin, fmax}}, ColorFunctionScaling -> True]]
(* give the same output *)
$\endgroup$
  • $\begingroup$ Oh, finally what I had in mind and that I could not express! So far I have never had this kind of problem, but now I understand how to solve it. Thank you! $\endgroup$ – TeM Jan 4 at 17:42
  • 1
    $\begingroup$ Updated to use the automatic rescaling feature of the ColorData[] gradients (ColorData[{"Rainbow", {fmin, fmax}}][f[r[u]]]), which I somehow forgot about for a little while. $\endgroup$ – Michael E2 Jan 6 at 20:50
3
$\begingroup$

Try

f[{x_, y_, z_}] := x^3 + y^3 + z^3;
r[u_] := {1/2 + 1/2 Cosh[u], Sqrt[2]/2 Sinh[u], 1/2 - 1/2 Cosh[u]};
{min, max} = {-ArcSinh[2 Sqrt[2]], ArcSinh[2 Sqrt[2]]};
mu = 0.2; 
mi = NMinValue[{f[r[u]], min <= u <= max}, u];
ma = NMaxValue[{f[r[u]], min <= u <= max}, u];
ParametricPlot3D[r[u], {u, min, max}, 
BoxRatios -> {1, 1, 1}, 
ColorFunction -> Function[{x, y, z, u}, 
ColorData["Rainbow"][mu f[r[u]]]],
ColorFunctionScaling -> False, AxesLabel -> {x, y, z}, 
PlotLegends -> BarLegend[{"Rainbow", 
{mi, mu(ma-mi)}}]]

enter image description here

$\endgroup$
  • $\begingroup$ Definitely better than everything red! Would there be a way to keep the numbers on the graduated scale unchanged? $\endgroup$ – TeM Jan 3 at 19:00

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.