14
$\begingroup$

I would like to have ArrayPlot[] also present the value of each cell in it, similar to the LabelingFunction that is available in other types of plots. How do I do it?

$\endgroup$

1 Answer 1

19
$\begingroup$

Like this?

SeedRandom[42, Method -> "Legacy"]; (* for reproducibility *)

mat = RandomReal[1, {3, 5}];
ArrayPlot[mat, 
          Epilog -> {Red, MapIndexed[Text[#1, Reverse[#2 - 1/2]] &, Reverse[mat], {2}]}, 
          Mesh -> True]

labeled ArrayPlot[]

$\endgroup$
9
  • $\begingroup$ +1, answers the question. How about a contrasting text color (black on white, white on black,..)? I won't be able to upvote a second time for it, though :-) $\endgroup$
    – stevenvh
    Commented Aug 26, 2012 at 16:15
  • $\begingroup$ @stevenvh I guess something like Round[1 - GrayLevel[...]] should do it $\endgroup$
    – rm -rf
    Commented Aug 26, 2012 at 16:16
  • $\begingroup$ That was my first idea as well, but at 50 % gray you won't see anything :-( $\endgroup$
    – stevenvh
    Commented Aug 26, 2012 at 16:19
  • $\begingroup$ yes thanks this is great $\endgroup$
    – Doron
    Commented Aug 26, 2012 at 16:21
  • $\begingroup$ @steven, $\gamma$-tweaking might do the trick in that case; I'll play around and edit this answer if I see something I like. $\endgroup$ Commented Aug 26, 2012 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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