Sorting $N$-ary Gray codes into a plane/grid

Is there a formal algorithm to arrange a set of "numbers" on a grid/plane such that each adjacent set differs from the other by only one value. Something similar to the Grey code but further extended or are we forced to go to multi-dimesnions?,

To make things clear, suppose we have a set comprised of $M$ numbers in the form of $(m_1,m_2,m_3)$, each digit can take up to the value $N$ where $N$ is always a single digit number. As an example suppose $M = 3$ and $N = 3$ therefore all the possible combinations are:

(0,0,0),(0,0,1),(0,0,2),(0,0,3),(1,0,0),(1,0,1),(1,0,2),(1,0,3)
(0,1,0),(0,1,1),(0,1,2),(0,1,3),(1,1,0),(1,1,1),(1,1,2),(1,1,3)
(0,2,0),(0,2,1),(0,2,2),(0,2,3),(1,2,0),(1,2,1),(1,2,2),(1,2,3)
(0,3,0),(0,3,1),(0,3,2),(0,3,3),(1,3,0),(1,3,1),(1,3,2),(1,3,3)
(2,0,0),(2,0,1),(2,0,2),(2,0,3),(3,0,0),(3,0,1),(3,0,2),(3,0,3)
(2,1,0),(2,1,1),(2,1,2),(2,1,3),(3,1,0),(3,1,1),(3,1,2),(3,1,3)
(2,2,0),(2,2,1),(2,2,2),(2,2,3),(3,2,0),(3,2,1),(3,2,2),(3,2,3)
(2,3,0),(2,3,1),(2,3,2),(2,3,3),(3,3,0),(3,3,1),(3,3,2),(3,3,3)


I need this because in what I am doing, each set has a corrosponding value and I need to plot those values and serach for maxima/minima later on. Thanks.

P.S. Are there any limitations on the shape? (i.e. square) or could it take any form (cross, rectangle)? Thanks.