Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Mathematica help it's written that:

ListDensityPlot[array] -> generates a smooth density plot from an array of values.

There is also an example:

 ListDensityPlot[{{1, 1, 1, 1}, {1, 2, 1, 2}, {1, 1, 3, 1}, {1, 2, 1, 4}}, Mesh -> All]

enter image description here

I understand when the input is in the form of $ \{ x, y, f(x,y)\}$, what this function does. But, I really cannot understand what this function does when it has an array as an input.

share|improve this question
What does the forth element mean in the example above? I think for density plot we mush have two value for coordinate and one value for the intensity or density in that coordinate. But in the example above I cannot find such a pattern. – MOON May 9 '14 at 15:54
please note the preamble in the documentation for the example: "Use an array of values to define heights for a density". See also ReliefPlot and see the effect of arrays of various sizes eg 7x 5 or whatever you like. Look through all the examples. – ubpdqn May 9 '14 at 16:36
up vote 9 down vote accepted

The answer about the pattern you are missing:

each value in an array is the value that generates color for Integer coordinates like (1,1) between those an interpolation is done by ListDensityPlot.

Matrices world:

  • First index refers to rows
  • First row is the top one

Graphics world

  • First coordinate refers to "columns"
  • First "row" refers to the bottom one.

enter image description here

        Background -> 
         Directive[Opacity@.8, Blend["Rainbow", #2[[1]]/4]], 
        ImageSize -> 35 {1, 1}, Alignment -> Center, 
        BaseStyle -> {Bold, White}] &, array, {2}], 
     Spacings -> 1.5 {1, 1}]
     BaseStyle -> 24, Mesh -> Full, MeshStyle -> White, 
     PlotRangePadding -> .5,
     Epilog -> {MapIndexed[
           Background -> 
            Directive[Opacity[4/#], Blend["Rainbow", #2[[1]]/4]], 
           ImageSize -> 35 {1, 1}, Alignment -> Center, 
           BaseStyle -> {Bold, White}], #2] &, array, {2}]},
     ImageSize -> 500, ImagePadding -> 45]

    }}, Alignment -> Center, Spacings -> 3]
share|improve this answer
@Kuba. Thank you for your elegant and beautiful answer. – MOON May 9 '14 at 17:52
@yashar I'm glad I could help :) Good luck. – Kuba May 9 '14 at 18:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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