# 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 Commented Feb 8, 2017 at 17:39
• You can also look here and here for graphical interfaces to create your own color function Commented Feb 8, 2017 at 17:45
• cf = ColorData[{"GreenPinkTones", {-30, 30}}][2 # + Abs@#] & Commented Feb 8, 2017 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. Commented Feb 8, 2017 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]}]],