2
$\begingroup$
cell = LatticeData["SimpleCubic", "Image"];
Graphics3D[Translate[cell[[1]], 2 Tuples[Range[3], 3]],   Boxed -> False]

I know this creates 4x4x4 lattice; how can I make it to graph 4x4x16 lattice? I have created a simple cubic lattice using graphics. Now, I wanna color code these points using (4,4,16) matrix containing 1's and 0's. So, my question is how can I do this?

I have created this plot using Python Scatter plot but I am trying to find a better way to visualize this using matthematica

$\endgroup$
2
$\begingroup$

Generate a $4 \times 4\times 16$ binary matrix using RandomInteger and replace 0s with Red and 1s with Green:

SeedRandom[1]
matrix = RandomInteger[1, {4, 4, 16}] /. {0 -> Red, 1 -> Green};

Use MapIndexed with level specification {3} to combine colors in matrix with spheres and cuboids placed in coordinates given by the index:

spheres = MapIndexed[{#, Sphere[#2, .15]} &, matrix, {3}];

cuboids =  MapIndexed[Cuboid @ #2 &, matrix[[;; -2, ;; -2, ;; -2]], {3}];

Graphics3D[{spheres, FaceForm[{Opacity[.1], Blue}], cuboids}, Boxed -> False]

enter image description here

Alternatively, generate coordinates using Outer and combine the coordinates with the colors from matrix using MapThread:

coords = Outer[List, Range[4], Range[4], Range[16]];

spheres = MapThread[{#, Sphere[#2, .15]} &, {matrix, coords}, 3];

cuboids = Map[Cuboid, coords[[;;-2, ;;-2, ;;-2]], {-2}];

Graphics3D[{spheres, FaceForm[{Opacity[.1], Blue}], cuboids}, Boxed -> False]

enter image description here

Note: You can use RandomChoice to get the 3D array of colors directly:

SeedRandom[1];
matrix2 = RandomChoice[{Red, Green}, {4, 4, 16}];

matrix2 == matrix

True

$\endgroup$
  • $\begingroup$ Very cute indeed :-) $\endgroup$ – chris Oct 28 '19 at 8:08

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.