There is one 2D List of data, like {{2,3,0},{1,0,0},{0,0,1}}, which I'd like to plot in the form of the following image (drawn with Adobe Illustrator):


Which has the following properties:

  1. Every small grid is colored corresponding to their number, like ArrayPlot
  2. For every number above a certain threshold, say 1, will be written on their grid, as shown. I would not want every number to be written and then hidden by coloring the grid with the same color, as the data I have is both large in dimension and sparse.
  3. This is essentially an overlapping of ArrayPlot and a partially shown Grid, but I couldn't figure out how to not draw every number.

So how can this be done with standard Mathematica functions?


1 Answer 1

a = {{2, 3, 0}, {1, 0, 0}, {0, 0, 1}}; 

ArrayPlot[Rescale[1 - a], 
 Mesh -> All,
 Epilog -> MapIndexed[If[# >= 1, Text[Style[#, Large], #2 - .5], {}] &, 
   Reverse /@ Transpose@a, {2}]]

enter image description here

  • $\begingroup$ Thanks! This is exactly what I've been looking for $\endgroup$
    – t-smart
    Commented Apr 4, 2021 at 1:55

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.