Consider the following sample code

 c[y_]:= Exp[-y];  

Plot[{f1[x], f2[x]}, {x, 0, 1}, 
     PlotStyle -> {ColorData["SolarColors", 0], ColorData["SolarColors", 1]}]

Plot[c[2 x - x], {x, 0, 1}]

I would like to have a filling that fills the area between the two curves f1[x],f2[x] by the values of c[f2[x]-f1[x]] in the following manner

  1. That the values of c[f1[x]] and c[f2[x]] will be the end values of the colordata.
  2. The area in between them will be a gradient fill with the colordata that is normalized according to c[f2[x]-f1[x]]

What I want is best presented in the figure

enter image description here

  • $\begingroup$ 1. It seems that the values of $c(x)$ do not fit between the two curves though. 2. What property of the filling should be influenced by the value of $c(x)$? Should the filling be within the two curves, or from one of the curves to the axis? I think you could perhaps clarify your question a bit. $\endgroup$
    – MarcoB
    May 9 '18 at 13:20
  • $\begingroup$ @MarcoB. Thanks, I've edited the question and title, hope it is better understood now. $\endgroup$
    – jarhead
    May 9 '18 at 13:50

Is this what you are looking for?

Plot[{f1[x], f2[x]}, {x, 0, 1}, Filling -> {1 -> {2}}, 
     ColorFunction -> Function[{x, y}, 
     Blend[{ColorData["SolarColors", 0], ColorData["SolarColors", 1]}, 
     c[(y - f2[x])/(f1[x] - f2[x])]]],
     ColorFunctionScaling -> False

enter image description here

It looks better if you normalise $\exp$ to the range $[0,1]$ instead of $[0,e^{-1}]\approx [0,.4]$:

c[y_] := (Exp[-y] - Exp[-1])/(1 - Exp[-1])

enter image description here

  • $\begingroup$ you should use ColorFunctionScaling->False here (this only works because your scale is 0-1 anyway.) $\endgroup$
    – george2079
    May 10 '18 at 18:06
  • $\begingroup$ @george2079 Thank you, but surely I must be missing something: if I add your option to my code, the figure becomes solid yellow: i.imgur.com/jtM7COp.png Do you know why? $\endgroup$ May 10 '18 at 19:15
  • $\begingroup$ you have the x and y reversed in the color function, c[(y - f1[x])/(f2[x] - f1[x])] $\endgroup$
    – george2079
    May 10 '18 at 19:54
  • $\begingroup$ @george2079 perfect, thank you! $\endgroup$ May 10 '18 at 19:59

You can also use parametricPlot with (ColorData["SolarColors"][c@#4] &) as the ColorFunction setting:

ParametricPlot[{x, t f1[x] + (1 - t) f2[x]}, {x, 0, 1}, {t, 0, 1}, 
 AspectRatio -> 1, Mesh -> None, BoundaryStyle -> None, 
 ColorFunction -> (ColorData["SolarColors"][c@#4] &)]

enter image description here


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.