9
$\begingroup$

Firstly, I'm not asking about blending a color gradient on a curve.

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.

$\endgroup$
9
  • $\begingroup$ Does something like Manipulate[Plot[x^2, {x, 0, 2}, PlotStyle -> ColorData[{"Rainbow", "Reverse"}, a]], {a, 0, 1}] work for you? $\endgroup$ Mar 17, 2016 at 3:49
  • $\begingroup$ 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. $\endgroup$
    – C. E.
    Mar 17, 2016 at 4:02
  • $\begingroup$ @C.E., I'm getting an error message : ColorData[{"Rainbow", "Reverse"}] is not a graphics directive.. I believe that "Reverse" is unknown (not sure). $\endgroup$
    – Cham
    Mar 17, 2016 at 4:05
  • $\begingroup$ The function color[T_] = ColorData["Rainbow"][(T - 1)/9];is working, but the colors are inverted. $\endgroup$
    – Cham
    Mar 17, 2016 at 4:11
  • $\begingroup$ 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}]. $\endgroup$ Mar 17, 2016 at 4:17

2 Answers 2

9
$\begingroup$
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]

enter image description here enter image description here

enter image description here

$\endgroup$
6
  • $\begingroup$ 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. $\endgroup$
    – Cham
    Mar 17, 2016 at 4:19
  • $\begingroup$ Is this what you wanted? $\endgroup$
    – mrz
    Mar 17, 2016 at 4:26
  • $\begingroup$ 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). $\endgroup$
    – Cham
    Mar 17, 2016 at 4:28
  • $\begingroup$ start a fresh new notebook and copy the code above ... delete you color function $\endgroup$
    – mrz
    Mar 17, 2016 at 4:37
  • $\begingroup$ The option "Reverse"doesn't seem to be recognized by MMA version 7. Is there another way to reverse the Rainbow ? $\endgroup$
    – Cham
    Mar 17, 2016 at 4:39
4
$\begingroup$
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}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.