Im trying to make a color function for listdensity that changes depending on the range of values in the array.

m1 = Array[# &, {10, 10}];
m1 = m1/Max[m1];
m2 = Array[# &, {10, 10}];
m2 = m2/Max[m2];
m2= Transpose[m2] + 2

My idea was to create a color function like this:

colors[z_] := Blend[{{0,White},{1, Blue},{2,White}, {3, Red},{4,White},{5, Green}}, z]

However this doesnt work, both plots come out from white to blue.

{ListDensityPlot[m1, PlotRange -> All, ColorFunction ->colors,InterpolationOrder -> 0],MatrixForm[N[m1]]}
{ListDensityPlot[m2, PlotRange -> All,ColorFunction->colors, InterpolationOrder -> 0],MatrixForm[N[m2] + 2]}

The end goal is to merge 3 arrays that are normalized to 1 and each has a specific color. Any ideas?

  • 2
    $\begingroup$ You need to set the option ColorFunctionScaling->False in ListDensityPlot and your solution will work. $\endgroup$ – N.J.Evans Apr 30 at 19:07

Your Answer

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

Browse other questions tagged or ask your own question.