# Mathematica: ListDensityPlot behavior different for arrays and points

I am using ListDensityPlot to output the results of a physical simulation. I've passed both an array of values and coordinates coupled with magnitudes to ListDensityPlot.

Although I expect identical functionality it seems the points are interpolated differently.

I've recreated the problem in a very simple case in this code:

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


Toggling the third element of a list in the first function call from 1 to 2 causes a change (since all are 1), and changing any element in a list in the second function call from 1 to 2 does the same.

The input in the first call should be identical to that in the second. However, it seems that ListDensityPlot is using a different algorithm for smoothing in each case. I have tried altering the order in the first call, but this changes nothing.

Am I missing something or is this a known feature that I will have to work around?

• Thank you to whoever migrated this topic. – Roberto Miguez Jul 9 '12 at 0:21

I think it is just the order in which the points are fed to the algorithm:

GraphicsGrid[{{
ListDensityPlot[{{1, 1, 2}, {2, 1, 1}, {1, 2, 1}, {2, 2, 1}}, Mesh -> All],
ListDensityPlot[{{2, 1}, {1, 1}}, Mesh -> All]}}] If you add a few more points, the effect of the points choosing sequence is diluted:

r = Table[{x, y, x + y}, {x, 10}, {y, 10}];
GraphicsGrid[{{ListDensityPlot[Flatten[r, 1], Mesh -> All],
ListDensityPlot[r[[All, All, 3]], Mesh -> All]}}] Edit

The problem behind the scenes is that in the first format {x,y, f[x,y]} Mma is calculating the nearest points to perform the interpolation, while in the second format Mma assumes a grid layout. When Mma calculates the euclidean distance between two points in your first case, as there are equal candidates, it chooses one that differs from the one used in the second algorithm.

You may tweak it if you need to:

me = \$MachineEpsilon;
GraphicsGrid[{{
ListDensityPlot[{{1, 1, 2}, {2 - me, 1, 1}, {1, 2, 1}, {2 - me, 2 - me, 1}}],
ListDensityPlot[{{2, 1}, {1, 1}}]}}] • Excellent, much appreciated belisarius. – Roberto Miguez Jul 9 '12 at 0:23