# How to define variable “Rainbow” curve colors?

I would like to make the curve color uniform on all its lenght instead, but the color should change dynamically while we slide a Manipulate slider. Secondly, the colors should be from the "Rainbow" color palette, going from "deep red" when the T parameter (temperature) takes its lowest value, and the color should gradually change to the "deep purple" color when T takes its highest value.

Here's a MWE example that shows the idea, using a simple variation of color linked to the temperature (I hope the idea is clear) :

color[T_] := RGBColor[1 (10 - T)/(10 - 1), 0, 1 (T - 1)/(10 - 1)]

Planck[T_, colorparameter_] := Plot[
(1/lambda)^5/(Exp[100/(T lambda)] - 1),
{lambda, 0, 10},
PlotPoints -> Automatic,
PlotRange -> All,
PlotStyle -> Directive[Thick, colorparameter],
PerformanceGoal -> "Quality"
]

Manipulate[
Show[
{Planck[T, color[T]]},
PlotRange -> All,
AspectRatio -> 1,
Frame -> True,
ImageSize -> {400, 400}
],
{
{T, 5, Style["T ( K ) ", 10]},
1, 10, 0.1,
ImageSize -> Large
},
ControlPlacement -> Bottom
]


Currently, the function color[T_] is not the proper one. It should be changed to something that uses the "Rainbow" palette.

• Does something like Manipulate[Plot[x^2, {x, 0, 2}, PlotStyle -> ColorData[{"Rainbow", "Reverse"}, a]], {a, 0, 1}] work for you? – J. M.'s technical difficulties Mar 17 '16 at 3:49
• What J.M. said, although for your situation it would be something like color[T_] = ColorData[{"Rainbow", "Reverse"}][(T - 1)/9]; since T goes from 1 to 10. – C. E. Mar 17 '16 at 4:02
• @C.E., I'm getting an error message : ColorData[{"Rainbow", "Reverse"}] is not a graphics directive.. I believe that "Reverse" is unknown (not sure). – Cham Mar 17 '16 at 4:05
• The function color[T_] = ColorData["Rainbow"][(T - 1)/9];is working, but the colors are inverted. – Cham Mar 17 '16 at 4:11
• Why not use a handy feature of ColorData[] to accept domains? Manipulate[Plot[x^2, {x, 0, 2}, PlotStyle -> ColorData[{"Rainbow", {10, 1}}, a]], {a, 1, 10}]. – J. M.'s technical difficulties Mar 17 '16 at 4:17

Clear[color];
color = ColorData[{"Rainbow", "Reverse"}];

Planck[T_, colorparameter_] :=
Plot[(1/lambda)^5/(Exp[100/(T lambda)] - 1), {lambda, 0, 10},
PlotPoints -> Automatic, PlotRange -> All,
PlotStyle -> Directive[Thick, colorparameter],
PerformanceGoal -> "Quality"]

max = 10;

Manipulate[
Show[{Planck[T, color[T/max]]}, PlotRange -> All, AspectRatio -> 1,
Frame -> True,
ImageSize -> {400, 400}], {{T, 5, Style["T ( K ) ", max]}, 1, max,
0.1, ImageSize -> Large}, ControlPlacement -> Bottom] • This is working, except that the colors are inverted. I need the deep purple to be associated to the highest value of T, while deep red is associated to the lowest value of T. – Cham Mar 17 '16 at 4:19
• Is this what you wanted? – mrz Mar 17 '16 at 4:26
• Well, when I slide the slider to 10, the curve turns red. At T = 1, the curve is bluish (or "deep purple"). It should be the reverse (red is associated to the lowest temperature). – Cham Mar 17 '16 at 4:28
• start a fresh new notebook and copy the code above ... delete you color function – mrz Mar 17 '16 at 4:37
• The option "Reverse"doesn't seem to be recognized by MMA version 7. Is there another way to reverse the Rainbow ? – Cham Mar 17 '16 at 4:39
tRange = {1, 10};
col[x_, range_] := ColorData["Rainbow"][1 - Rescale[x, range]]

Manipulate[Plot[x^-5/(Exp[100/(t x)] - 1), {x, 0, 10},
PlotStyle -> Directive[Thick, col[t, tRange]]],
{{t, 5, Style["T (K) ", Last@tRange]}, Sequence @@ tRange, 0.1}]