# Creating a labeled grid of colored squares

I'd like to help some students with their project and I need to come up with a nice way of producing the following image:

The numbers will probably be loaded in a vector, such as:

v={4,7,8,10,14,3,15,9,0,1,2,5,12,6,11,13}


Now, the exact coloring and shading is not necessary, but I would like to see several ideas if possible.

Perhaps a variation on the following theme?

numbers = {4, 7, 8, 10, 14, 3, 15, 9, 0, 1, 2, 5, 12, 6, 11, 13};

Grid[
Map[
Framed[#,
ContentPadding -> True, ImageSize -> {60, 60},
Alignment -> Center,
FrameStyle -> Directive[Darker@Red, Thick],
Background -> Directive[Lighter@Pink, Opacity[0.4]]
] &,
ArrayReshape[
Style[#, 32, Italic, FontFamily -> "Serif"] & /@ ToString /@ numbers,
{4, 4}
],
{2}
]
]


• Thank you. There is a lot to learn here and this image is precisely what my students will need. This is extremely helpful. – David Nov 15 '16 at 20:49
• @David Glad to help! – MarcoB Nov 15 '16 at 23:24

Just another way:

v = {4, 7, 8, 10, 14, 3, 15, 9, 0, 1, 2, 5, 12, 6, 11, 13};
With[{p = Reverse /@ (Transpose@Partition[v, 4]),
z = ConstantArray[0, {4, 4}]},
Show[
ArrayPlot[z, Mesh -> True,
ColorRules -> {0 -> LightRed},
MeshStyle -> Directive[Purple, Thickness[0.02]],
Epilog ->
MapIndexed[Text[Style[#1, 28], #2 - {1/2, 1/2}] &, p, {2}]],
ArrayPlot[z, ColorRules -> {_ -> None}, Mesh -> True,
MeshStyle -> Directive[White, Thickness[0.01]]]]]


• Thanks for the assistance. I'm going to look carefully at this. – David Nov 16 '16 at 7:12
• To help with locating each piece of text, is there a way to add ticks to the outer frame that indicate the position of each text number. I tried z=ConstantArray[0,{4,4}], then ArrayPlot[z, Mesh -> True, Frame -> True, FrameTicks -> All], but the ticks give the two and column number. – David Nov 16 '16 at 23:48
• @David Apologies for delay. Reverse/@Transpose[Partition[v,4] puts matrix into a format to allow placement of text consistent with the coordinate system of the graphic. ArrayPlot is just a container and overlaying meshes just a device to get the framed appearance.. MapIndexed places the transformed matrix in the positions of the graphic with the offset to make them central. The left hand lower corner is {0,0} and the other corners going counter-clockwise are {4,0}, {4,4},{0,4}. MapIndexed just subtracts {1/2,1/2}. For middle of square {m,n}->{m,n}-{1/2,1/2}. I hope this makes sense. – ubpdqn Nov 17 '16 at 2:53
• It does, thanks. – David Nov 17 '16 at 19:17