Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

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

1 Answer 1

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

enter image description here

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

enter image description here

We can change that with the option:

DensityPlot[
 Sin[ x ] Sin[ y ], { x , -4 , 4 } ,
 { y, -3 , 3 } ,
 ColorFunction -> ColorData[ "SunsetColors" ] ]

enter image description here

Similarly, we can add a rescaling step:

DensityPlot[
 Sin[ x ] Sin[ y ], { x , -4 , 4 } ,
 { y, -3 , 3 } ,
 ColorFunction -> (ColorData["SunsetColors"][#^(3/8)] &) ]

enter image description here

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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