I want to create a custom ColorFunction
using RGBColor
for my DensityPlot
. A nice example is provided in the ColorFunction
documentation under "applications".
I'm trying to get this coloring:
- If zero: set color to Black.
- If positive: increase Blue.
- If negative: increase Red.
My code looks like this:
DensColor[ z_ ] := RGBColor[If[z < 0, -z, 0], 0, (z + Abs[z])/2]
f[x_, y_] := x*y - 1
DensityPlot[f[x, y], {x, -2, 2}, {y, -2, 2}, PlotRange -> Full, ColorFunction -> DensColor, PlotLegends -> Automatic]
Unfortunately, it gives blue for positive (correct), but still some dark-blue for zero (wrong), and no red at all (wrong).
Can anyone explain why this isn't working as I expected?
ColorFunctionScaling->False
$\endgroup$ColorFunctionScaling
. $\endgroup$ColorFunctionScaling
to see the difference, for example [i.stack.imgur.com/Dud45.png]. $\endgroup$ColorFunctionScaling->True
(which is the default), Mathematica delivers values to the color function that are scaled to lie between 0 and 1. This is also the range that the CoolColor function in the example expects. $\endgroup$