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)?


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


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