0
$\begingroup$

We are trying to plot a density plot using the TemperetarueMap colour scheme. However, we don't seem to be able to make the white colour correspond to the value zero of the function we are plotting.

It is important for us to be able to set the white colour to represent zero because we need the highest contrast between positive and negative values of the plotted function.

We have already tried for some time to find the best way to do that but we couldn't. Does anyone have any insight on this matter?

Any help will be greatly appreciated.

$\endgroup$
3
$\begingroup$

By default, most plotting function re-scale the values they compute to lie inbetween 0 and 1, then this value is passed to the colour function. TemperatureMap is white for 0.5, so the white colour will correspond to the average of the minimum and maximum values that DensityPlot computed in the given plot domain.

You need to override this automatic scaling using ColorFunctionScaling -> False and provide a manual domain for the colour function which matches the values of your function.

For example,

DensityPlot[Sin[Sqrt[x^2 + y^2]], {x, -5, 5}, {y, -5, 5},
 ColorFunction -> ColorData[{"TemperatureMap", {-1, 1}}],
 ColorFunctionScaling -> False
]

Here I manually determined that all function values are between -1 and 1 and I chose a matching range for the colour function that is also symmetric around 0, meaning that white will correspond to 0.

$\endgroup$
2
$\begingroup$

For example:

Plot3D[Exp[-x^2 - y^2] - Exp[-(x - 1)^2 - (y - 1)^2], 
       {x, -2, 2}, {y, -2, 2}, ColorFunction -> (ColorData["TemperatureMap", #3 + .5] &), 
        ColorFunctionScaling -> False]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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