# How to correctly map values onto an arrayplot

I want to understand why the order of the text is reversed from what it should be? If I compare the first and second results, I see that the {1,1}, {2,2},... diagonal is going down the wrong diagonal. How could I alter this, such that the order is correct? For reference, here is the original question...ArrayPlot with cells labeled by corresponding values

SeedRandom[41, Method -> "Legacy"];(*for reproducibility*)
mat = RandomReal[1, {4, 4}]
ArrayPlot[
mat,
Epilog -> {Red, MapIndexed[
Text[#1, Reverse[#2 - 1/2]] &, mat, {2}]},
Mesh -> True, ImageSize -> 400]

mat = RandomReal[1, {4, 4}]
ArrayPlot[
mat,
Epilog -> {Red, MapIndexed[
Text[#2, Reverse[#2 - 1/2]] &, mat, {2}]},
Mesh -> True, ImageSize -> 400]

• Your code doesn't work. Oct 4, 2014 at 23:39
• @Pickett code has been updated, had a rogue Style command that I removed. Thanks! Oct 4, 2014 at 23:50
• I think you forgot to include the Reverse. Reread J.M.'s answer, he uses Reverse[mat]. Oct 5, 2014 at 0:10
• @DumpsterDoofus yes, you are correct. Thanks for the extra set of eyes. Lol, I feel sheepish now! Oct 5, 2014 at 0:17
• @tarhawk: It still doesn't fix your second example, but it's a step in the right direction. Oct 5, 2014 at 0:21

SeedRandom[41, Method -> "Legacy"];

(mat = RandomReal[1, {4, 4}]) // TableForm


 ArrayPlot[
mat,
Epilog ->
MapIndexed[Text[Framed[#1, Background -> White], #2 - 1/2] &,
Transpose@Reverse@mat, {2}],
Mesh -> True,
PlotTheme -> "Detailed",
ImageSize -> 400]


Update

To handle negative values you must specify a "matching" PlotRange

SeedRandom[41, Method -> "Legacy"];
mat = Round[RandomReal[{-1, 1}, {4, 4}], 0.01];

ArrayPlot[
mat,
ColorFunction -> "RedGreenSplit",
Epilog ->
MapIndexed[Text[Framed[#1, Background -> White], #2 - 1/2] &,
Transpose@Reverse@mat, {2}],
Mesh -> True,
PlotRange -> {-1, 1},
PlotTheme -> "Detailed",
ImageSize -> 400]


• I believe that you the first argument of ArrayPlot should be mat as your values do not correspond to correct shades Oct 5, 2014 at 12:27
• @ubpdqn Thank you very much - updated :)
– eldo
Oct 5, 2014 at 12:38
• @eldo The additional transpose also did the trick for the ordering. Oct 5, 2014 at 13:54