# Understanding the difference between matrix indices and image coordinates in context of ListDensityPlot

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]


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.

-
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

## 1 Answer

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.

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]

-
@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