Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to set color to a rectangle (in fact a line) that lies on (0,0) and (1,0), and the color function is given by $u(x,t)=t(x-x^2), 0\leq t\leq1$. Since, this $u(x,t)$ act as temperature at the point $(x,0)$ at time $t$, I want to use the colordata with "TemperatureMap", the following is what I have tried:

u[x_, t_] := t (x - x^2)
Animate[Plot[0, {x, 0, 1}, 
 AxesOrigin -> {0, 0}, 
 PlotRange -> {{0, 1}, {-0.02, 0.25}}, 
 PlotStyle -> {Thick}, 
 ColorFunction -> (ColorData["TemperatureMap"][u[#, t]]) &],
{t, 0, 1}]

I find that it must be some problem in the ColorFunction, but I can't fix it, any suggestion?


I have tried your code, and find it shall works as the first answer, but since my original question (not posted here) is tried to solving the following question,

f[x_] := -x^2 + x
equ = {D[u[t, x], t] == D[u[t, x], x, x],
u[0, x] == f[x],
u[t, 0] == f[0],
u[t, 1] == f[1]};
sol = NDSolve[equ, u, {t, 0, 1}, {x, 0, 1}]
HeatConda = Animate[Show[{
Plot[Evaluate[u[t, x] /. sol], {x, 0, 1}, 
 PlotRange -> {-0.1, 0.25}, AxesOrigin -> {0, 0}, 
 Filling -> Axis, 
 ColorFunction -> (ColorData["TemperatureMap"][#2] &)],
Plot[-0.04, {x, 0, 1}, PlotStyle -> {Thick},
 ColorFunction ->
  Function[{x, y}, 
   ColorData["TemperatureMap"][Evaluate[u[t, x] /. sol]]]]}],
 {t, 0, 0.4}]

I want to color the bottom line as the same as the filling color. I first tried to simplify the question to the one post here, but the solution here still can work for my (original) question, so please help me again?

The Figure

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

ColorFunction [] doesn't always perform proper scaling:

f[x_] := -x^2 + x
equ = {D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == f[x],  u[t, 0] == f[0], u[t, 1] == f[1]};
sol = NDSolve[equ, u, {t, 0, 1}, {x, 0, 1}];
g[t_, x_] := Evaluate[u[t, x] /. sol][[1]];
{min, max} = {FindMinValue[{g[0, x], x > 0}, {x, 0}],
              FindMaxValue[{g[0, x], x > 0}, {x, 0}]}
HeatConda =
 Animate[Show[{
    Plot[g[t, x], {x, 0, 1},
     PlotRange -> {-0.1, 0.25},
     AxesOrigin -> {0, 0},
     Filling -> Axis,
     ColorFunction -> (ColorData["TemperatureMap"][#2] &)],
    Plot[-.05, {x, 0, 1}, 
     PlotStyle -> Thick,
     ColorFunction -> (ColorData["TemperatureMap"][Rescale[g[0., #1], {min, max}]] &)]
    }], {t, 0, 0.4}]

Mathematica graphics

share|improve this answer
    
That's what I needed! –  van abel Jan 18 '13 at 14:56
    
May I ask what's exact relation between the value of the ColorData["TemperatureMap", t] and the Temperature t? –  van abel Jan 18 '13 at 14:59
    
@vanabel Read the ColorFunction option help. It usually normalizes its output, however in this particular case I did it myself. –  belisarius Jan 18 '13 at 15:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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