Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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. –  yashar May 9 at 15:54
1  
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 at 16:36
add comment

1 Answer 1

up vote 5 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

Panel@Grid[{
   {MatrixForm@array,
    Grid[MapIndexed[
      Framed[#, 
        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}]
    ,
    ListDensityPlot[array,
     BaseStyle -> 24, Mesh -> Full, MeshStyle -> White, 
     PlotRangePadding -> .5,
     Epilog -> {MapIndexed[
        Inset[Framed[#, 
           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
1  
@Kuba. Thank you for your elegant and beautiful answer. –  yashar May 9 at 17:52
    
@yashar I'm glad I could help :) Good luck. –  Kuba May 9 at 18:23
add comment

Your Answer

 
discard

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.