Shading of cubes in 3D picture

The example here is just great (and even better with the implementation in the comment).

I would, however, like to have all the sides on a cube in the same color but have the color change in each layer of cubes.

Here is the code (and a MWE of it's usage):

% Plane partition
\documentclass{minimal}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength{\PreviewBorder}{5pt}

\begin{comment}
:Title: Plane partition

Illustration of a plane partition'.

Plane partition: http://mathworld.wolfram.com/PlanePartition.html
\end{comment}

% 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} {
\setcounter{y}{-1}
\foreach \b in \a {
\setcounter{z}{-1}
\foreach \c in {0,...,\b} {
\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}


I have never used TikZ (and I do not have the time to learn it at the moment), so I would be very glad if someone would change the code for me to achive the desired result.

P.S. I have also posted this question here.

-
On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are "too localized". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – Andrew Uzzell Oct 9 '12 at 14:04
@ Andrew Uzzell: I have tried to modify my initial post. I do not know how to make the question "less localized" since I would like to be helped with something concrete. – Svend Tveskæg Oct 9 '12 at 14:13

This particular example you chose is actually not very hard to read for the task you want. The actual drawing of the cubes is irrelevant. Hence you don't bother too much with TikZ.

The interesting point is that the layers are drawn for a value of the counter z. It is stepped in the definition of \planepartition in the last \foreach statement:

\foreach \c in {0,...,\b} {
...


This tells us that here the different planes are drawn.

The macro \c will loop through the values from 0 to \b (its actual value again is irrelevant). For each of these values the macro \c will hold the current values. We can use this to change the color depending on the layer.

The colors right now are in the three definitions for \topside, \leftside and \rightside when it reads

fill=<color>


Let's change all three cases into

fill=cubecolor


Now there are several possibilities. We could add something like \colorlet{cubecolor}{red!\c0} right after \addtocounter{z}{1}

\foreach \c in {0,...,\b} {
\colorlet{cubecolor}{red!\c0}
...


to get different shadings of red:

We could also define different colors depending on the value of \c. Let's define the following macro:

\newcommand*\cubecolors[1]{%
\ifcase#1\relax
\or\colorlet{cubecolor}{green}%
\or\colorlet{cubecolor}{yellow}%
\or\colorlet{cubecolor}{blue}%
\or\colorlet{cubecolor}{red}%
\or\colorlet{cubecolor}{purple}%
\or\colorlet{cubecolor}{cyan}%
\else
\colorlet{cubecolor}{white}%
\fi
}


and add it at the same place:

\foreach \c in {0,...,\b} {
\cubecolors{\c}
...


We'll get:

-
Very nice, especially the second example! – Tom Bombadil Oct 9 '12 at 22:20

I made a few little modifications, you now can get a gradient between two colors:

Code

\documentclass[tikz,border=5mm]{standalone}
\usepackage{xifthen}
\usepackage{verbatim}

\begin{comment}
:Title: Plane partition

Illustration of a plane partition'.

Plane partition: http://mathworld.wolfram.com/PlanePartition.html
\end{comment}

% 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]{%
\pgfmathsetmacro{\cpercent}{\mincolor+(\maxcolor-\mincolor)/(\maxz-1)*#3}
\fill[fill=cubecolorhigh!\cpercent!cubecolorlow, 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]{%
\pgfmathsetmacro{\cpercent}{\mincolor+(\maxcolor-\mincolor)/(\maxz-1)*#3}
\fill[fill=cubecolorhigh!\cpercent!cubecolorlow, 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]{%
\pgfmathsetmacro{\cpercent}{\mincolor+(\maxcolor-\mincolor)/(\maxz-1)*#3}
\fill[fill=cubecolorhigh!\cpercent!cubecolorlow, 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} {
\setcounter{y}{-1}
\foreach \b in \a {
\setcounter{z}{-1}
\foreach \c in {0,...,\b} {
\cube{\value{x}}{\value{y}}{\value{z}}}
}
}
}
}

\begin{document}

\pgfmathsetmacro{\maxz}{5}% height of the highest tower
\pgfmathsetmacro{\mincolor}{20}% minimal percentage on gradient from lower to upper color (0-100)
\pgfmathsetmacro{\maxcolor}{80}% maximal percentage on gradient from lower to upper color (0-100)
\colorlet{cubecolorlow}{orange!75!gray}% color definition for low color (see xcolor manual)
\colorlet{cubecolorhigh}{blue!50!lime}% color definition for high color (see xcolor manual

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

\pgfmathsetmacro{\maxz}{10}
\pgfmathsetmacro{\mincolor}{0}
\pgfmathsetmacro{\maxcolor}{100}
\colorlet{cubecolorlow}{blue}
\colorlet{cubecolorhigh}{red}

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

\end{document}


Output

-

Here is another solution proposal, based on the following contributions:

With (e.g.) \tdplotsetmaincoords{\alpha}{\beta}, you can rotate your 3D-Figure so that it shows the desired perspective. This is especially useful for translucent plane partitions, since with Kim's code, the plane frames look rather confusing in that case.
However, the results are only satisfactory if one looks at the positive x-, y- and z-faces. I started implementing all other cases as well. Unfortunately, there were some unforseen challenges, which I haven't dealt with yet (shouldn't be too big of a problem, though):

• If one looks, e.g., at the negative x- and y-faces and the positive z-face, one has to change the order, in which the layers are created (e.g., from front to back instead of from back to front).

• The package tikz-3dplot has some problems that need to be fixed and I seem to be exploiting those. These issues occurs, if the z-axis should point down - it still points up in my example (see bottom-right figure).

% Title: Plane partition
% =============================================================================
%
% Code taken from and inspired by:
% -----------------------------------------------------------------------------
% http://www.texample.net/tikz/examples/plane-partition/
% http://www.latex-community.org/know-how/440-tikz-3dplot

\documentclass{minimal}

\usepackage{ifthen}
\usepackage{xcolor}

\usepackage{pgfplots}
\pgfplotsset{compat = 1.3}
\usepackage{tikz-3dplot}

% =============================================================================
% =============================================================================

% Cube side length
\newcommand\CubeLength{1.25}

% =============================================================================

% Cube side: x-value is positive
\newcommand\CubeXpos[6]% {Length}{x-Shift}{y-Shift}{z-Shift}...%
%                     ...{x-Color}{Opacity}
{%
\ifthenelse{\equal{#5}{0}}%
{%
\pgfmathsetmacro{\CubeColorPercent}%
{%
(#4/#1)
}
%
\colorlet{CubeColorNew}{CubeHighColor!\CubeColorPercent!CubeLowColor}
}%
{%
\colorlet{CubeColorNew}{#5}
}
%
\colorlet{CubeColor}{CubeColorNew}
%
\fill[%
draw = black, fill = CubeColor, fill opacity = {#6}%
] ({#1+#2}, {#3}, {#4}) -- ({#1+#2}, {#1+#3}, {#4})%
-- ({#1+#2}, {#1+#3}, {#1+#4}) -- ({#1+#2}, {#3}, {#1+#4}) -- cycle;
}

% Cube side: x-value is negative
\newcommand\CubeXneg[6]% {Length}{x-Shift}{y-Shift}{z-Shift}...%
%                     ...{x-Color}{Opacity}
{%
\ifthenelse{\equal{#5}{0}}%
{%
\pgfmathsetmacro{\CubeColorPercent}%
{%
(#4/#1)
}
%
\colorlet{CubeColorNew}{CubeHighColor!\CubeColorPercent!CubeLowColor}
}%
{%
\colorlet{CubeColorNew}{#5}
}
%
\colorlet{CubeColor}{CubeColorNew}
%
\fill[%
draw = black, fill = CubeColor, fill opacity = {#6}%
] ({#2}, {#3}, {#4}) -- ({#2}, {#1+#3}, {#4})%
-- ({#2}, {#1+#3}, {#1+#4}) -- ({#2}, {#3}, {#1+#4}) -- cycle;
}

% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

% Cube side: y-value is positive
\newcommand\CubeYpos[6]% {Length}{x-Shift}{y-Shift}{z-Shift}...%
%                     ...{y-Color}{Opacity}
{%
\ifthenelse{\equal{#5}{0}}%
{%
\pgfmathsetmacro{\CubeColorPercent}%
{%
(#4/#1)
}
%
\colorlet{CubeColorNew}{CubeHighColor!\CubeColorPercent!CubeLowColor}
}%
{%
\colorlet{CubeColorNew}{#5}
}
%
\colorlet{CubeColor}{CubeColorNew}
%
\fill[%
draw = black, fill = CubeColor, fill opacity = {#6}%
] ({#1+#2}, {#1+#3}, {#4}) -- ({#2}, {#1+#3}, {#4})%
-- ({#2}, {#1+#3}, {#1+#4}) -- ({#1+#2}, {#1+#3}, {#1+#4}) -- cycle;
}

% Cube side: y-value is negative
\newcommand\CubeYneg[6]% {Length}{x-Shift}{y-Shift}{z-Shift}...%
%                     ...{y-Color}{Opacity}
{%
\ifthenelse{\equal{#5}{0}}%
{%
\pgfmathsetmacro{\CubeColorPercent}%
{%
(#4/#1)
}
%
\colorlet{CubeColorNew}{CubeHighColor!\CubeColorPercent!CubeLowColor}
}%
{%
\colorlet{CubeColorNew}{#5}
}
%
\colorlet{CubeColor}{CubeColorNew}
%
\fill[%
draw = black, fill = CubeColor, fill opacity = {#6}%
] ({#2}, {#3}, {#4}) -- ({#1+#2}, {#3}, {#4})%
-- ({#1+#2}, {#3}, {#1+#4}) -- ({#2}, {#3}, {#1+#4}) -- cycle;
}

% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

% Cube side: z-value is positive
\newcommand\CubeZpos[6]% {Length}{x-Shift}{y-Shift}{z-Shift}...%
%                     ...{z-Color}{Opacity}
{%
\ifthenelse{\equal{#5}{0}}%
{%
\pgfmathsetmacro{\CubeColorPercent}%
{%
(#4/#1)
}
%
\colorlet{CubeColorNew}{CubeHighColor!\CubeColorPercent!CubeLowColor}
}%
{%
\colorlet{CubeColorNew}{#5}
}
%
\colorlet{CubeColor}{CubeColorNew}
%
\fill[%
draw = black, fill = CubeColor, fill opacity = {#6}%
] ({#2}, {#3}, {#1+#4}) -- ({#1+#2}, {#3}, {#1+#4})%
-- ({#1+#2}, {#1+#3}, {#1+#4}) -- ({#2}, {#1+#3}, {#1+#4}) -- cycle;
}

% Cube side: z-value is negative
\newcommand\CubeZneg[6]% {Length}{x-Shift}{y-Shift}{z-Shift}...%
%                     ...{z-Color}{Opacity}
{%
\ifthenelse{\equal{#5}{0}}%
{%
\pgfmathsetmacro{\CubeColorPercent}%
{%
(#4/#1)
}
%
\colorlet{CubeColorNew}{CubeHighColor!\CubeColorPercent!CubeLowColor}
}%
{%
\colorlet{CubeColorNew}{#5}
}
%
\colorlet{CubeColor}{CubeColorNew}
%
\fill[%
draw = black, fill = CubeColor, fill opacity = {#6}%
] ({#2}, {#3}, {#4}) -- ({#2+#1}, {#3}, {#4})%
-- ({#2+#1}, {#3+#1}, {#4}) -- ({#2}, {#3+#1}, {#4}) -- cycle;
}

% -----------------------------------------------------------------------------

% Cube
\newcommand\Cube[9]% {Length}{x-Shift}{y-Shift}{z-Shift}...%
%                 ...{x-Color}{y-Color}{z-Color}{Opacity}{Orientation}
{%  {Length}{x-Shift}{y-Shift}{z-Shift}{Color}{Opacity}

\ifthenelse{\equal{#9}{PPP}}%
{%

\CubeXneg{#1}{#2}{#3}{#4}{white}{0}%
\CubeYneg{#1}{#2}{#3}{#4}{white}{0}%
\CubeZneg{#1}{#2}{#3}{#4}{white}{0}%

\CubeXpos{#1}{#2}{#3}{#4}{#5}{#8}%
\CubeYpos{#1}{#2}{#3}{#4}{#6}{#8}%
\CubeZpos{#1}{#2}{#3}{#4}{#7}{#8}%

}%
{}

%\ifthenelse{\equal{#9}{NPP}}%
%{%
%
%\CubeXpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeYneg{#1}{#2}{#3}{#4}{white}{0}%
%\CubeZneg{#1}{#2}{#3}{#4}{white}{0}%
%
%\CubeXneg{#1}{#2}{#3}{#4}{#5}{#8}%
%\CubeYpos{#1}{#2}{#3}{#4}{#6}{#8}%
%\CubeZpos{#1}{#2}{#3}{#4}{#7}{#8}%
%
%}%
%{}
%
%\ifthenelse{\equal{#9}{PNP}}%
%{%
%
%\CubeXneg{#1}{#2}{#3}{#4}{white}{0}%
%\CubeYpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeZneg{#1}{#2}{#3}{#4}{white}{0}%
%
%\CubeXpos{#1}{#2}{#3}{#4}{#5}{#8}%
%\CubeYneg{#1}{#2}{#3}{#4}{#6}{#8}%
%\CubeZpos{#1}{#2}{#3}{#4}{#7}{#8}%
%
%}%
%{}
%
%\ifthenelse{\equal{#9}{NNP}}%
%{%
%
%\CubeXpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeYpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeZneg{#1}{#2}{#3}{#4}{white}{0}%
%
%\CubeXneg{#1}{#2}{#3}{#4}{#5}{#8}%
%\CubeYneg{#1}{#2}{#3}{#4}{#6}{#8}%
%\CubeZpos{#1}{#2}{#3}{#4}{#7}{#8}%
%
%}%
%{}

% .........................................................................

%\ifthenelse{\equal{#9}{PPN}}%
%{%
%
%\CubeXneg{#1}{#2}{#3}{#4}{white}{0}%
%\CubeYneg{#1}{#2}{#3}{#4}{white}{0}%
%\CubeZpos{#1}{#2}{#3}{#4}{white}{0}%
%
%\CubeXpos{#1}{#2}{#3}{#4}{#5}{#8}%
%\CubeYpos{#1}{#2}{#3}{#4}{#6}{#8}%
%\CubeZneg{#1}{#2}{#3}{#4}{#7}{#8}%
%
%}%
%{}
%
%\ifthenelse{\equal{#9}{NPN}}%
%{%
%
%\CubeXpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeYneg{#1}{#2}{#3}{#4}{white}{0}%
%\CubeZpos{#1}{#2}{#3}{#4}{white}{0}%
%
%\CubeXneg{#1}{#2}{#3}{#4}{#5}{#8}%
%\CubeYpos{#1}{#2}{#3}{#4}{#6}{#8}%
%\CubeZneg{#1}{#2}{#3}{#4}{#7}{#8}%
%
%}%
%{}
%
%\ifthenelse{\equal{#9}{PNN}}%
%{%
%
%\CubeXneg{#1}{#2}{#3}{#4}{white}{0}%
%\CubeYpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeZpos{#1}{#2}{#3}{#4}{white}{0}%
%
%\CubeXpos{#1}{#2}{#3}{#4}{#5}{#8}%
%\CubeYneg{#1}{#2}{#3}{#4}{#6}{#8}%
%\CubeZneg{#1}{#2}{#3}{#4}{#7}{#8}%
%
%}%
%{}
%
%\ifthenelse{\equal{#9}{NNN}}%
%{%
%
%\CubeXpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeYpos{#1}{#2}{#3}{#4}{white}{0}%
%\CubeZpos{#1}{#2}{#3}{#4}{white}{0}%
%
%\CubeXneg{#1}{#2}{#3}{#4}{#5}{#8}%
%\CubeYneg{#1}{#2}{#3}{#4}{#6}{#8}%
%\CubeZneg{#1}{#2}{#3}{#4}{#7}{#8}%
%
%}%
%{}

}

% -----------------------------------------------------------------------------

% Three counters for shifting cubes
\newcounter{CubeCountX}
\newcounter{CubeCountY}
\newcounter{CubeCountZ}

% Set of cubes
\newcommand\CubeSet[7]% {Length}{SetCharacterization}...%
%                    ...{Left-Color}{Right-Color}{Top-Color}...%
%                    ...{Opacity}{Orientation}
{%
\setcounter{CubeCountX}{-1}
\foreach \a in {#2}%
{
\setcounter{CubeCountY}{-1}
\foreach \b in \a%
{
\setcounter{CubeCountZ}{-1}
\foreach \c in {0, ..., \b}%
{
\ifthenelse{\c = 0}%
{%
\setcounter{CubeCountZ}{-1}%
}%
{%  {Length}...%
%...{x-Shift}{y-Shift}{z-Shift}...%
%...{Left-Color}{Right-Color}{Top-Color}%
%...{Opacity}{Orientation}
\Cube{#1}%
{#1*\value{CubeCountX}}{#1*\value{CubeCountY}}%
{#1*\value{CubeCountZ}}%
{#3}{#4}{#5}%
{#6}{#7}%
}
}
}
}
}

% =============================================================================
% =============================================================================

\begin{document}

% -----------------------------------------------------------------------------

\noindent%
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{40}{120}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
%
\draw [dotted, white] (0,0,0) -- (+\CubeLength*1.5, 0, 0);
\draw [dotted, black] (0,0,0) -- (-\CubeLength*1.5, 0, 0);
\draw [dotted, white] (0,0,0) -- (0, +\CubeLength*1.5, 0);
\draw [dotted, black] (0,0,0) -- (0, -\CubeLength*1.5, 0);
\draw [dotted, white] (0,0,0) -- (0, 0, +\CubeLength*1.5)%
node [anchor = south, yshift = +10mm, color = black] {OK};
\draw [dotted, black] (0,0,0) -- (0, 0, -\CubeLength*1.5);
%
\draw [{}-{>}] (0,0,0) -- (\CubeLength*1.33, 0, 0)%
node [anchor = west] {$x$};
\draw [{}-{>}] (0,0,0) -- (0, \CubeLength*1.33, 0)%
node [anchor = west] {$y$};
\draw [{}-{>}] (0,0,0) -- (0, 0, \CubeLength*1.33)%
node [anchor = west] {$z$};

% Draw a set of cubes
\CubeSet{\CubeLength}{{1}}{red}{blue}{green}{0.9}{PPP}
%
\end{tikzpicture}%
%
\hspace*{1mm}%
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{40}{210}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
%
\draw [dotted, white] (0,0,0) -- (+\CubeLength*1.5, 0, 0);
\draw [dotted, black] (0,0,0) -- (-\CubeLength*1.5, 0, 0);
\draw [dotted, white] (0,0,0) -- (0, +\CubeLength*1.5, 0);
\draw [dotted, black] (0,0,0) -- (0, -\CubeLength*1.5, 0);
\draw [dotted, white] (0,0,0) -- (0, 0, +\CubeLength*1.5)%
node [anchor = south, yshift = +10mm, color = black] {OK};
\draw [dotted, black] (0,0,0) -- (0, 0, -\CubeLength*1.5);
%
\draw [{}-{>}] (0,0,0) -- (\CubeLength*1.33, 0, 0)%
node [anchor = west] {$x$};
\draw [{}-{>}] (0,0,0) -- (0, \CubeLength*1.33, 0)%
node [anchor = west] {$y$};
\draw [{}-{>}] (0,0,0) -- (0, 0, \CubeLength*1.33)%
node [anchor = west] {$z$};

% Draw a set of cubes
\CubeSet{\CubeLength}{{1}}{red}{blue}{green}{0.9}{PPP}
%
\end{tikzpicture}%
%
\hspace*{1mm}%
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{40}{300}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
%
\draw [dotted, white] (0,0,0) -- (+\CubeLength*1.5, 0, 0);
\draw [dotted, black] (0,0,0) -- (-\CubeLength*1.5, 0, 0);
\draw [dotted, white] (0,0,0) -- (0, +\CubeLength*1.5, 0);
\draw [dotted, black] (0,0,0) -- (0, -\CubeLength*1.5, 0);
\draw [dotted, white] (0,0,0) -- (0, 0, +\CubeLength*1.5)%
node [anchor = south, yshift = +10mm, color = black] {OK};
\draw [dotted, black] (0,0,0) -- (0, 0, -\CubeLength*1.5);
%
\draw [{}-{>}] (0,0,0) -- (\CubeLength*1.33, 0, 0)%
node [anchor = west] {$x$};
\draw [{}-{>}] (0,0,0) -- (0, \CubeLength*1.33, 0)%
node [anchor = west] {$y$};
\draw [{}-{>}] (0,0,0) -- (0, 0, \CubeLength*1.33)%
node [anchor = west] {$z$};

% Draw a set of cubes
\CubeSet{\CubeLength}{{1}}{red}{blue}{green}{0.9}{PPP}
%
\end{tikzpicture}%
%
\hspace*{1mm}%
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{40}{30}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
%
\draw [dotted, white] (0,0,0) -- (+\CubeLength*1.5, 0, 0);
\draw [dotted, black] (0,0,0) -- (-\CubeLength*1.5, 0, 0);
\draw [dotted, white] (0,0,0) -- (0, +\CubeLength*1.5, 0);
\draw [dotted, black] (0,0,0) -- (0, -\CubeLength*1.5, 0);
\draw [dotted, white] (0,0,0) -- (0, 0, +\CubeLength*1.5)%
node [anchor = south, yshift = +10mm, color = black] {Not OK};
\draw [dotted, black] (0,0,0) -- (0, 0, -\CubeLength*1.5);
%
\draw [{}-{>}] (0,0,0) -- (\CubeLength*1.33, 0, 0)%
node [anchor = west] {$x$};
\draw [{}-{>}] (0,0,0) -- (0, \CubeLength*1.33, 0)%
node [anchor = west] {$y$};
\draw [{}-{>}] (0,0,0) -- (0, 0, \CubeLength*1.33)%
node [anchor = west] {$z$};

% Draw a set of cubes
\CubeSet{\CubeLength}{{1}}{red}{blue}{green}{0.9}{PPP}
%
\end{tikzpicture}\\\rule{\textwidth}{0.25mm}\\

% -----------------------------------------------------------------------------

\noindent%
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{70}{150}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
\draw [->] (0,0,0) -- (3*\CubeLength*1.33, 0, 0) node [anchor = west]%
{$x$};
\draw [->] (0,0,0) -- (0, 3*\CubeLength*1.33, 0) node [anchor = west]%
{$y$};
\draw [->] (0,0,0) -- (0, 0, 3*\CubeLength*1.33) node [anchor = west]%
{$z$ OK};
%
% Draw a set of cubes
\CubeSet{\CubeLength}{{3,3,3},{3,2,1},{3,1,1}}%
{red}{blue}{green}{1.0}{PPP}
%
\end{tikzpicture}%
%
\hspace*{10mm}
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{70}{330}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
\draw [->] (0,0,0) -- (3*\CubeLength*1.33, 0, 0)%
node [anchor = west] {$x$};
\draw [->] (0,0,0) -- (0, 3*\CubeLength*1.33, 0)%
node [anchor = west] {$y$};
\draw [->] (0,0,0) -- (0, 0, 3*\CubeLength*1.33)%
node [anchor = west] {$z$: Not OK};
%
% Draw a set of cubes
\CubeSet{\CubeLength}{{3,3,3},{3,2,1},{3,1,1}}%
{red}{blue}{green}{1.0}{PPP}
%
\end{tikzpicture}\\\rule{\textwidth}{0.25mm}\\

% -----------------------------------------------------------------------------

\renewcommand\CubeLength{0.75}

\pgfmathsetmacro{\CubeMaxHeight}{5} % Height of the highest tower
\colorlet{CubeLowColor}{red} % Definition of the low color
\colorlet{CubeHighColor}{blue} % Definition of the high color
%
\noindent%
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{65}{120}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
\draw [->] (0,0,0) -- (4*\CubeLength*1.33, 0, 0)%
node [anchor = west] {$x$};
\draw [->] (0,0,0) -- (0, 4*\CubeLength*1.33, 0)%
node [anchor = west] {$y$};
\draw [->] (0,0,0) -- (0, 0, 5*\CubeLength*1.33)%
node [anchor = west] {$z$ OK};
%
% Draw a set of cubes
\CubeSet{\CubeLength}{{5,5,3,4},{4,4,3,3},{3,3,2,1},{1,0,2}}%
{0}{0}{0}{0.9}{PPP}
%
\end{tikzpicture}%
%
\hspace*{10mm}%
%
% Rotate the coordinate system with the help of the package 'tikz-3dplot'
\tdplotsetmaincoords{295}{300}%
%
\begin{tikzpicture}[x = 1.0cm, y = 1.0cm, z = 1.0cm, tdplot_main_coords]
%
% Draw the axes
\draw [->] (0,0,0) -- (4*\CubeLength*1.33, 0, 0)%
node [anchor = west] {$x$};
\draw [->] (0,0,0) -- (0, 4*\CubeLength*1.33, 0)%
node [anchor = west] {$y$};
\draw [->] (0,0,0) -- (0, 0, 5*\CubeLength*1.33)%
node [anchor = west] {$z$ Not OK, axis mathematically wrong};
%
% Draw a set of cubes
\CubeSet{\CubeLength}{{5,5,3,4},{4,4,3,3},{3,3,2,1},{1,0,2}}%
{0}{0}{0}{0.9}{PPP}
%
\end{tikzpicture}

% -----------------------------------------------------------------------------

\end{document}


Here's the result:

-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Christian Hupfer Jan 2 '15 at 17:39
This looks really interesting. Nice! – Svend Tveskæg Jan 3 '15 at 6:17