Part of this recent question involves coloring a ParametricPlot3D
of three variables from a set of ODEs according to a fourth variable. I just figured out how to do that using the slot #4
, but ColorFunctionScaling->True
doesn't seem to behave properly.
First, solve the ODEs:
nsp = 4;
{r[1], r[2], r[3], r[4]} = {1, 0.72, 1.53, 1.27};
{k[1], k[2], k[3], k[4]} = {1, 1, 1, 1};
amat = {{1, 1.09, 1.52, 0}, {0, 1, 0.44, 1.36}, {2.33, 0, 1, 0.47}, {1.21, 0.51, 0.35, 1}};
Do[a[i, j] = amat[[i, j]], {i, nsp}, {j, nsp}];
eqns = Table[x[i]'[t] ==
r[i]*x[i][t]*(1 - Sum[a[i, j]*x[j][t]/k[i], {j, nsp}]), {i, nsp}];
ics = Table[x[i][0] == 0.1, {i, nsp}];
unks = Table[x[i], {i, nsp}];
tmax = 10000;
sol = NDSolve[{eqns, ics}, unks, {t, 0, tmax}][[1]];
It looks good with ColorFunctionScaling->False
:
ParametricPlot3D[Evaluate[{x[1][t], x[2][t], x[3][t]} /. sol], {t, 100, tmax},
AxesLabel -> {"x1", "x2", "x3"}, PlotPoints -> 400,
ColorFunction -> (ColorData["SunsetColors", x[4][#4] /. sol] &),
ColorFunctionScaling -> False]
but totally weird with ColorFunctionScaling->True
:
ParametricPlot3D[Evaluate[{x[1][t], x[2][t], x[3][t]} /. sol], {t, 100, tmax},
AxesLabel -> {"x1", "x2", "x3"}, PlotPoints -> 400,
ColorFunction -> (ColorData["SunsetColors", x[4][#4] /. sol] &),
ColorFunctionScaling -> True]
We can see what it should look like by manually applying our own scaling directly to the ColorFunction
:
max = NMaximize[{x[4][t] /. sol, 0 < t < tmax}, t, Method -> "RandomSearch"][[1]];
min = NMinimize[{x[4][t] /. sol, 0 < t < tmax}, t, Method -> "RandomSearch"][[1]];
ParametricPlot3D[Evaluate[{x[1][t], x[2][t], x[3][t]} /. sol], {t, 100, tmax},
AxesLabel -> {"x1", "x2", "x3"}, PlotPoints -> 400,
ColorFunction -> (ColorData["SunsetColors", (x[4][#4] - min)/(max - min) /. sol] &),
ColorFunctionScaling -> False]
Bug or user error? :) v11.1 on MacOS.
ColorFunctionScaling -> True
" - not really; per the docs, values rescaled to $[0, 1]$ are what get fed to theColorFunction
, instead of values in $[100,10000]$. $\endgroup$x[4][#4] /. sol
would be scaled to $[0,1]$ not the#4
, to match my last graph. ?? $\endgroup$t
-values (#4
) that get scaled. To convince yourself, try catching the values being used:ColorFunction -> ((Echo[#4]; ColorData["SunsetColors", x[4][#4] /. sol]) &)
$\endgroup$