# How to set zero of bicolor ColorData?

Let me pose the question through an example:

Normally, to set the ColorFunction for, say, a ListDensityPlot, I would write

myColorFunc = ColorData[{"GreenPinkTones", {-30, 10}}];
ColorFunctionScaling -> False;


In this example, though, the white of the ColorFunction comes at -10, whilst I would like to have shades of Green from -30 to 0, and shades of Pink from 0 to 10. How can I achieve this?

• cf = Blend[{{-30, Green}, {0, White}, {10, Pink}}, #] &; BarLegend[{cf, {-30, 10}}] see Blend – Jason B. Feb 8 '17 at 17:39
• You can also look here and here for graphical interfaces to create your own color function – Jason B. Feb 8 '17 at 17:45
• cf = ColorData[{"GreenPinkTones", {-30, 30}}][2 # + Abs@#] & – Simon Woods Feb 8 '17 at 21:49

You could make your own bi-linear mapping:

myColorFunc = (ColorData["GreenPinkTones"][
Piecewise[{
{Rescale[#, {-30, 0 }, {0, 1/2}], # < 0},
{Rescale[#, {0  , 10}, {1/2, 1}], # >= 0}}]]) &;

BarLegend[{myColorFunc, {-30, 10}},LegendLayout -> "Row"]


• Thank you very much. This gets the job done. Thanks also to @JasonB. for his input. Both the solutions work well. This is a great community. – Marce Feb 8 '17 at 22:30

Another way to shift the position of a middle color of a gradient uses the "bias" function of Schlick (with suitable rescaling) along with a color gradient. Here is a small demo:

bias[h_, x_] := bias[h, x, {0, 1}];
bias[h_, x_, {a_, b_}] := a + (x - a)/(1 + (1/h - 2) (1 - (x - a)/(b - a)))

Manipulate[DensityPlot[x, {x, -30, 10}, {y, 0, 5}, AspectRatio -> Automatic,
ColorFunction -> Function[x, ColorData[{gradient, {-30, 10}},
bias[h, x, {-30, 10}]]],
ColorFunctionScaling -> False, FrameTicks -> {Automatic, None},
PlotLabel -> Row[{"h=", Round[h, 0.001]}]],
Control[{{h, 0.5}, 0, 1}]}, Spacer[20]]]


where we see through experimentation that setting h = 0.25 shifts the white color to 0. To confirm:

Solve[bias[h, 0, {-30, 10}] == bias[1/2, Mean[{-30, 10}], {-30, 10}], h]
{{h -> 1/4}}


Thus, here is the final color function you need:

mycf = ColorData[{"GreenPinkTones", {-30, 10}}, bias[1/4, #, {-30, 10}]] &;
BarLegend[{mycf, {-30, 10}}, LegendLayout -> "Row"]