Many plotting functions accept the ColorFunction
argument, which you can use to pass a function that will generate colors for each plotted point. Here is an example:
ColorData[ "LakeColors" ]

It is a function that returns color values:
ColorData[ "LakeColors" ][ .5 ]
RGBColor[ 0.663226 , 0.687282 , 0.911765 ]
The {0,1}
means this function will map any value in the range [0, 1] to the depicted color spectrum. By default, functions that accept the ColorFunction
option rescale their values to this range, but you can prevent this with the option ColorFunctionScaling -> False
. In general you would not use this unless you are passing in a custom color function with a different domain. There are also "indexed" color schemes that are appropriate for discrete data. See Color Schemes
in the documentation.
"LakeColors"
is the default color scheme for DensityPlot
:
DensityPlot[
Sin[ x ] Sin[ y ], { x , -4 , 4 } ,
{ y, -3 , 3 } ]

We can change that with the option:
DensityPlot[
Sin[ x ] Sin[ y ], { x , -4 , 4 } ,
{ y, -3 , 3 } ,
ColorFunction -> ColorData[ "SunsetColors" ] ]

Similarly, we can add a rescaling step:
DensityPlot[
Sin[ x ] Sin[ y ], { x , -4 , 4 } ,
{ y, -3 , 3 } ,
ColorFunction -> (ColorData["SunsetColors"][#^(3/8)] &) ]

I removed the - .5
from your method because that creates negative values here. Any transformation you attach to a ColorFunction
option should map from [0, 1] to [0, 1] when you are using default color functions.
ColorFunction
option. For example:ColorFunction -> (ColorData["SunsetColors"][(# - .5)^(3/8)] &)
$\endgroup$