I'm having troubles applying colors to a simple 3D curve plot. Here's the code :

Color1 = RGBColor[0, 0, 1];
Color2 = RGBColor[1, 0, 0];
Color3 = RGBColor[0, 1, 0];

CouleurLigne[t_] := Blend[{Color1, Color2, Color3},  Rescale[t, {Tmin, Tmax}]]

Tmin = 0;
Tmax = 4 Pi;

ParametricPlot3D[{Sin[t], Cos[t], t}, {t, Tmin, Tmax}, PlotStyle -> {Directive[AbsoluteThickness[1]]}, ColorFunction -> (CouleurLigne[#] &), MaxRecursion -> 7, PerformanceGoal -> "Quality"]

I'm getting the curve with the first color applied to it. No blending from color1 to color3. What am I doing wrong here ?

  • $\begingroup$ Just a note that your Color1, Color2, Color3 are Blue, Red, Green, respectively. $\endgroup$
    – murray
    Aug 3 '15 at 16:26

The arguments for ColorFunction in ParametricPlot3D are (from the docs):

ParametricPlot3D x, y, z, u or x, y, z, u, v

so you need #4, which is t.

As for the ColorFunctionScaling, I suggest you to read the docs and experiment a little. But just as a hint, you may eliminate both the ColorFunction -> False option AND the Rescale thing in your CouleurLigne definition to get the same result :)

ParametricPlot3D[{Sin[t], Cos[t], t}, {t, Tmin, Tmax}, 
 PlotStyle -> AbsoluteThickness@2, 
 ColorFunction -> (CouleurLigne[#4] &), ColorFunctionScaling -> False]

Mathematica graphics

  • $\begingroup$ Wow, thanks for the answer. But why the ColorFunctionScaling -> False option ? And why #4 ? $\endgroup$
    – Cham
    Aug 3 '15 at 1:43

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.