# Sharpening extrema using DensityPlot

I have a data set where I really care mainly about visualizing the highest and lowest areas. DensityPlot suits my needs well, but ideally the maxima and minima would pop more from the rest of the data. I know that DensityPlot scales the data from your function to between zero and one before coloring it accordingly. I'd like to use a scaling that has more meat in the middle than theirs. So I was thinking I could take their scaling, and use it as an input to for example

 (x-0.5)^3/8,


which has the properties f[0]=0 and f[1]=1, but is better distributed for my purpose. Then I'd pass these values to the colorizer.

Can't really figure out how to do this though. Any thoughts?

• Look at the ColorFunction option. For example: ColorFunction -> (ColorData["SunsetColors"][(# - .5)^(3/8)] &) Jun 3, 2014 at 0:10
• @mfvonh - please consider expanding on your comment as an answer with some graphical examples. Jun 3, 2014 at 10:33

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.