3
$\begingroup$

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:

enter image description here

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.

Thanks for your time.

$\endgroup$
5
$\begingroup$

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}
 ]
]

Mathematica graphics

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

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]]]]]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for the assistance. I'm going to look carefully at this. $\endgroup$ – David Nov 16 '16 at 7:12
  • $\begingroup$ 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. $\endgroup$ – David Nov 16 '16 at 23:48
  • $\begingroup$ @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. $\endgroup$ – ubpdqn Nov 17 '16 at 2:53
  • $\begingroup$ It does, thanks. $\endgroup$ – David Nov 17 '16 at 19:17

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.