# How do I place a graphical marker (box, circle, …) in a MatrixPlot?

I'm trying to locate minima / maxima in matrices on a heat map. So I have my 2D matrix and did a MatrixPlot,

and I can find the position of the smallest value.

My question: how do I place a graphical marker at that position? Like a box to outline field (7,6)?

Completely stumped.

-
Use the Epilog option. –  Szabolcs Jan 30 '13 at 18:04
Thanks, Szabolcs! Works just as expected! imgur.com/uArxaPM –  blinkenstack Jan 30 '13 at 18:40
Overlay could work too, but may be more difficult to position. Another possibility is to use Show –  Sjoerd C. de Vries Jan 30 '13 at 18:43
If you want an unfilled Rectangle, use {EdgeForm[Black], FaceForm[None], Rectangle[...]}. –  Szabolcs Jan 30 '13 at 18:44
Okay, 'Overlay' did work as well, though with more overhead. The unfilled box Szabolcs suggested is actually what I was fiddling with just now: link - thank you, good sirs! –  blinkenstack Jan 31 '13 at 14:58

To position the highlight rectangle properly, the array position of the highlighted value must be converted into a graphics coordinate. For a data array of $n$ rows, to highlight the value at row $i$ and column $j$ requires the bottom left corner of the rectangle to be placed at graphics coordinate $\{j-1, n-i\}$

Example:

highlight[data_, patt_, directives_] :=
{FaceForm[None], EdgeForm[directives],
Rectangle[{#2 - 1, Length[data] - #1}] & @@@ Position[data, patt]}

data = N@Table[x^2 + y^2, {x, -4, 3, 6/11}, {y, -4, 3, 6/11}];

MatrixPlot[data, Epilog -> {
highlight[data, Min[data], {Thick, Red}],
highlight[data, x_ /; 5 < x < 6, {Blue, Dashed}]
}]


-