4
$\begingroup$

Consider the following ArrayPlot.

ArrayPlot[RandomInteger[{1, 10}, {4, 5}], Mesh -> {{1, 2}, {4}}, 
 MeshStyle -> Directive[Red, Thick]]

Mesh option allow to control the entire horizontal and vertical meshes but i want to control the mesh for individual cells. I for example want a Mesh around cell at position {2,3} but only on its left and bottom side. How do I do this?

$\endgroup$
6
$\begingroup$

You can add lines in desired positions using Epilog:

SeedRandom[1]
mat = RandomInteger[{1, 10}, {4, 5}];
ArrayPlot[mat, 
 Epilog -> {Thick, Red, CapForm["Butt"], Line[{{2, 3}, {2, 2}, {3, 2}}]}]

enter image description here

Update: A function that add lines to cells in ArrayPlot:

ClearAll[addLines]
addLines[cells : {{_, _} ..}, o : OptionsPattern[ArrayPlot]] := 
  Module[{k = Length @ #},
   ArrayPlot[#, o, 
     Epilog -> {Thick, Red, CapForm["Butt"], 
       Line[{{#[[2]] - 1, k - #[[1]] + 1}, {#[[2]] - 1, 
            k - #[[1]]}, {#[[2]], k - #[[1]]}} & /@ cells]}]] &;

Example:

SeedRandom[1]
mat = RandomInteger[{1, 10}, {6, 15}];

addLines[{{4, 7}, {2, 5}, {5, 10}}, ColorFunction -> "Pastel", Mesh -> All][mat]

enter image description here

$\endgroup$

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.