# Set the scale in ColorFunction [duplicate]

The following plot (A)

 ListLinePlot[{0,1,2,3},ColorFunction->"TemperatureMap"]


The following plot (B)

ListLinePlot[{4,5,6,7},ColorFunction->"TemperatureMap"]


goes also from blue to read.

I want the colors to be correlated to the number to be plotted, not the position in the list (as above). Therefore I would like (A) to go from white to yellow (approx.) and (B) from yellow to red (approx.).

How can I make the color to be correlated with the value of the number to be plotted and not the position in the list?

• Yeah....this is no duplicate. It's related, but not nearly a duplicate. – jvriesem Dec 8 '15 at 22:17

Your problem is due to the fact, that the default setting is ColorFunctionScaling -> True. You'll have to set ColorFunctionScaling -> False with the downside, that you'll now have to take care of a proper scaling:

ListLinePlot[{0, 1, 2, 3}, ColorFunction -> (ColorData["TemperatureMap", #2/7] &),
ColorFunctionScaling -> False]


ListLinePlot[{4, 5, 6, 7}, ColorFunction -> (ColorData["TemperatureMap", #2/7] &),
ColorFunctionScaling -> False]


• how could I fix the ColorFunction, such that I can see a blue->green colour gradient in a y axes range of 0.05 (f. ex. -0.04<y<0.01). I tried to play around with the number multiplying #2, but I did not succeed. – Mencia Mar 27 '15 at 13:51
• @Mencia ColorFunction -> (Blend[{Blue, Green}, (#2 + 0.04)/0.05] &) should give you the desired result. – Karsten 7. Mar 27 '15 at 14:18
• Thanks great! Let say now, that I do ...Blend[{Blue,White,Green}... and that I want the center of the white span to be at y=0 always, i.e., to have a symmetric Colour Gradient around y=0 (White). How can I do this? – Mencia Mar 27 '15 at 14:28
• @Mencia ColorFunction -> (Blend[{{-0.04, Blue}, {0, White}, {0.01, Green}}, #2] &)? – Karsten 7. Mar 27 '15 at 14:33
• @Mencia Or ColorFunction -> (Blend[{{-0.04, Blue}, {0, White}, {0.04, Green}}, #2] &) depending on what you mean with symmetric. – Karsten 7. Mar 27 '15 at 14:35

Your plots has {1,2,3,4} and {1,2,3} for the values of x, and, unless an explicit function is used as the ColorFunction the default argument is taken to be x. Hence the same color in both of your plots. If you want the color to change with y you need to use a function that specifies that dependence:

 ListLinePlot[{0, 1, 2, 3}, ColorFunction -> "TemperatureMap",
PlotStyle -> Thickness[.02],
ColorFunction -> Function[{x, y}, ColorData["TemperatureMap"][y]]]
(* or ColorFunction -> (ColorData["TemperatureMap", #2] &) *)


 ListLinePlot[{4, 5, 6}, ColorFunction -> "TemperatureMap",
PlotStyle -> Thickness[.02],
ColorFunction -> Function[{x, y}, ColorData["TemperatureMap"][y]]]


You can also use the same rescaled color function for both plots:

Row[ListLinePlot[#, PlotStyle -> Thickness[.02], PlotLabel -> #,
ImageSize -> 400, ColorFunctionScaling -> False,
ColorFunction -> Function[{x, y},
ColorData[{"TemperatureMap", {-6, 6}}][y]]] & /@
{{0, 1, 2, 3}, {4, 5, 6}}]