[Tex/LaTex] TikZ: Plane partitions with labeled faces

tikz-pgf

The example here gives the code for drawing plane partitions with TikZ. I want to do two things at once:

  1. Label the top faces of the top cubes shown in any plane partition with a numeral that indicates the number of cubes in that stack. (The numeral should be slanted, of course.)
  2. Change the angles in the plane partition so that the viewer seems to be looking down at the plane partition "from a higher vantage point" than what the code currently yields. (The angles for the axes could be adjusted from the current 210, -30, 90 angles to, say, 220, 40, 90.) I want to do this so that I can draw stacked cubes, like plane partitions, but with the possibility that some of the "inner" (closest) cubes are higher than those cubes stacked against the walls.

Any help would be greatly appreciated. Here is a MWE (taken from the example above):

% Plane partition
% Author: Jang Soo Kim
\documentclass{minimal}
\usepackage{tikz}
% Three counters
\newcounter{x}
\newcounter{y}
\newcounter{z}

% The angles of x,y,z-axes
\newcommand\xaxis{210}
\newcommand\yaxis{-30}
\newcommand\zaxis{90}

% The top side of a cube
\newcommand\topside[3]{
  \fill[fill=yellow, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (0,1) --(150:1)--(0,0);
}

% The left side of a cube
\newcommand\leftside[3]{
  \fill[fill=red, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (0,-1) -- (210:1) --(150:1)--(0,0);
}

% The right side of a cube
\newcommand\rightside[3]{
  \fill[fill=blue, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (-30:1) --(0,-1)--(0,0);
}

% The cube 
\newcommand\cube[3]{
  \topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}

% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\newcommand\planepartition[1]{
 \setcounter{x}{-1}
  \foreach \a in {#1} {
    \addtocounter{x}{1}
    \setcounter{y}{-1}
    \foreach \b in \a {
      \addtocounter{y}{1}
      \setcounter{z}{-1}
      \foreach \c in {1,...,\b} {
        \addtocounter{z}{1}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}

\begin{document} 

\begin{tikzpicture}
\planepartition{{5,3,2,2},{4,2,2,1},{2,1},{1}}
\end{tikzpicture}

\end{document} 

Best Answer

Not sure it fits the requirements, but at the very least it's fairly easy to play with:

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[x=(220:1cm), y=(-40:1cm), z=(90:0.707cm)]

\foreach \m [count=\y] in {{5,3,2,2},{4,2,2,1},{2,1},{1}}{
  \foreach \n [count=\x] in \m {
  \ifnum \n>0
      \foreach \z in {1,...,\n}{
        \draw [fill=blue!30] (\x+1,\y,\z) -- (\x+1,\y+1,\z) -- (\x+1, \y+1, \z-1) -- (\x+1, \y, \z-1) -- cycle;
        \draw [fill=blue!40] (\x,\y+1,\z) -- (\x+1,\y+1,\z) -- (\x+1, \y+1, \z-1) -- (\x, \y+1, \z-1) -- cycle;
        \draw [fill=blue!10] (\x,\y,\z)   -- (\x+1,\y,\z)   -- (\x+1, \y+1, \z)   -- (\x, \y+1, \z) -- cycle;  
      }
      \node at (\x+0.5, \y+0.5, \n) {\n};
 \fi
 }
}    

\end{tikzpicture}

\end{document}

enter image description here