# Gamma correction on mycolor

How to add a Gamma correction like gamma[x_?NumericQ, ɣ_] := x^(1/ɣ) to my color function ?

data = Table[{#, #2, Sin[#] Cos[#2]} & @@ RandomReal[{-3, 3}, 2], {1000}];

myTemperatureMap[f_] := Blend[
{ {0., Blue}, {.25, Lighter@LightBlue}, {.25, White}
, {.75, White}, {.75, Yellow}, {1., Red}
}
, f];

DensityPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3}
, PlotPoints -> 100
, ColorFunction -> myTemperatureMap
, PlotLegends -> Automatic
]

A color like Brown is a RGBColor expression, with arguments you can manipulate with standard tools, e.g. MapAt:

Table[MapAt[#^(1/γ) &, Brown, ;; 3], {γ, {0.4, 1, 2.2}}]

gamma[γ_][c_?ColorQ] := MapAt[#1^(1/γ) &, ColorConvert[c, "RGB"], ;; 3]

myTM[γ_] :=
gamma[γ] @ Blend[{{0., Blue}, {.25, Lighter@LightBlue}, {.25, White},
{.75, White}, {.75, Yellow}, {1., Red}}, #] &;

DensityPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 100,
ColorFunction -> myTM[0.1], PlotLegends -> Automatic]

DensityPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3}, PlotPoints -> 100,
ColorFunction -> myTM[2.2], PlotLegends -> Automatic]

### With array data

data = {#, #2, Sin[#] Cos[#2]} & @@@ RandomReal[{-3, 3}, {8000, 2}];

ListDensityPlot[data, ColorFunction -> myTM[0.1], PlotLegends -> Automatic]

• Thanks if my data is a list of 3 column how to change it because when I change the func sin[x]*cos[y] by my data it doesn’t work Jul 3, 2018 at 13:46
• @Bigprophete ListDensityPlot[data, ColorFunction -> myTM[2.2], PlotLegends -> Automatic] ? Jul 4, 2018 at 5:40
• @creidhne I tried this ListDensityPlot[data, ColorFunction -> myTM[0.1], ColorFunctionScaling -> False, PlotLegends -> Automatic] Jul 4, 2018 at 6:45
• @Bigprophete I'm not sure I understand. Please see my update. Is that what you want? Jul 4, 2018 at 10:47
• Seems to be working thanks a lot Jul 4, 2018 at 11:45