I have some data that I would like to display in an ArrayPlot. I like the default color scheme of ListDensityPlot (Mathematica 10); is there a way I can use that same color scheme in ArrayPlot? In other words, how can I extract the default ColorFunction used in ListDensityPlot (or DensityPlot)?

  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey Sep 28 '15 at 1:42

Here is a sample array with {x, y, z} values

array = {{1, 0, 0, 0.3}, {1, 1, 0, 0.3}, {1, 0, 1, 0.7}}

We make a ListDensityPlot

listDensityPlot = ListDensityPlot[array]

which produces

Mathematica graphics

We are lucky because we can "see" the color function using options:


I won't show them all but one item of interest is:

"DefaultColorFunction" -> "M10DefaultDensityGradient"

So all that need be done is

ArrayPlot[array, ColorFunction -> "M10DefaultDensityGradient"]

which results in

Mathematica graphics

  • $\begingroup$ Did not know about Options, looks very useful in general. Thanks! $\endgroup$ – giraffamatica Oct 1 '15 at 0:11

OK I found a simple if unelegant solution.

The idea is to turn off ColorFunctionScaling and generate a list of DensityPlots where each DensityPlot just shows a constant value from 0 to 1, then take the color from each plot and interpolate between them. Certainly not the most efficient solution but it works.

defaultColorGetter[zVal_] := DominantColors[ListDensityPlot[zVal*{{1, 1}, {1, 1}}, Frame -> False, ColorFunctionScaling -> False], 1][[1]];
colors = Table[defaultColorGetter[z], {z, 0, 1, 0.1}];
approximateDefaultColorFunction[z_] := Blend[colors, z];

Setting ColorFunction -> approximateDefaultColorFunction in ArrayPlot now gives the desired behavior:

enter image description here


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.