3
$\begingroup$

Can I write text, or add a specific text label to individual squares of an ArrayPlot[...] graphic? Specifically, I would like to assign an two-dimensional integer coordinate label to each square.

$\endgroup$
4
$\begingroup$

There might be an easier way, but what about this:

array = RandomInteger[100, {10, 10}];
arrayPlot = ArrayPlot[array, ImageSize -> 500, PlotRangePadding -> 0]

grid 1

numbers = 
 Graphics[{White, 
   Table[Text[ 
      StringJoin[ToString /@ {n , ", ", m}], 
   {n - 0.5, m - 0.5}], 
   {n, 1, 10}, {m, 1, 10}]}]

Show[arrayPlot, numbers]

grid 2

$\endgroup$
1
$\begingroup$

Coordinates in the form needed by Part:

data = RandomReal[1, {5, 7}];

{x, y} = Dimensions @ data;

f[x_, y_, shift_] := Array[Text[{x - #2 + 1, #}, {##} - shift] &, {y, x}]

ArrayPlot[data, Epilog -> {Black, f[x, y, 0.49], White, f[x, y, 0.51]}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Clever text styling! Embossing by the Boss. $\endgroup$ – cormullion Jan 8 '13 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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