# Help with ColorFunction [duplicate]

I'm trying to graph a list of data with ListDensityPlot. My idea is to color negative values in red, zero in white and positive values in blue. I created a ColorFunction using Blend:

cf = Blend[{Blue,White,Red},#]&
ListDensityPlot[mydata, ColorFunction -> cf, PlotLegends -> Automatic]


Right now when I graph my data white is around -3. I could manually "center" my data, but I'm wondering whether there is a way to "center" the graph around white (zero) on the fly (by supplying options to ListDensityPlot or modifying cf).

• Have you seen this? Jul 17 '16 at 3:33
• This helps, but I find LogisticSigmoid to be too sharp around 0 and with not much variation for Abs[x] > 4. I guess I could find a better function. Jul 17 '16 at 3:55
• You can tune LogisticSigmoid's argument of course, to make the "s" more or less steep. Jul 17 '16 at 5:31
• True, actually that is more elegant. I ended up using cf = Blend[{Blue, White, Red}, LogisticSigmoid[#/3]] &. Jul 17 '16 at 5:44
• …and of course, if LogisticSigmoid[] still doesn't suit you, there's ArcTan[], Tanh[], Erf[] Jul 17 '16 at 6:07

One simple option:

ListDensityPlot[mydata,
ColorFunction -> (Blend[{{-10, Blue}, {0, White}, {5, Red}}, #] &),
ColorFunctionScaling -> False, PlotLegends -> Automatic]


A simple way to control blend:

minLegend = Min[mydata[[;; , -1]]];
maxLegend = Max[mydata[[;; , -1]]];
spdLegend = 2;

cf = Blend[{{minLegend , Blue}, {minLegend / spdLegend, LightBlue}, {0, White},
{maxLegend / spdLegend, LightRed}, {maxLegend , Red}}, #] &;

ListDensityPlot[mydata, ColorFunction -> cf,
ColorFunctionScaling -> False, PlotLegends -> Automatic]


• Very nice! I guess I could also dynamically change the extremes with Min[data[[;;,-1]]] and Max[data[[;;,-1]]]. How do I change the "speed" of the blend? Jul 17 '16 at 3:59
• @amrods cf = Blend[{{-10, Blue}, {-5, LightBlue}, {0, White}, {2.5, LightRed}, {5, Red}}, #] &; you could control when LightBlue and LightRed start based on the desired speed. Jul 17 '16 at 4:12
• I see, awesome. Jul 17 '16 at 4:13