2
$\begingroup$

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
]
$\endgroup$

1 Answer 1

2
$\begingroup$

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}}]

enter image description here

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]

enter image description here

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

enter image description here


With array data

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

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

enter image description here

$\endgroup$
5
  • $\begingroup$ 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 $\endgroup$ Jul 3, 2018 at 13:46
  • $\begingroup$ @Bigprophete ListDensityPlot[data, ColorFunction -> myTM[2.2], PlotLegends -> Automatic] ? $\endgroup$
    – creidhne
    Jul 4, 2018 at 5:40
  • $\begingroup$ @creidhne I tried this ListDensityPlot[data, ColorFunction -> myTM[0.1], ColorFunctionScaling -> False, PlotLegends -> Automatic] $\endgroup$ Jul 4, 2018 at 6:45
  • $\begingroup$ @Bigprophete I'm not sure I understand. Please see my update. Is that what you want? $\endgroup$
    – Mr.Wizard
    Jul 4, 2018 at 10:47
  • $\begingroup$ Seems to be working thanks a lot $\endgroup$ Jul 4, 2018 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.