[Tex/LaTex] How to draw cubes in a 3 dimensional plane

3ddiagramstikz-pgf

So I want to draw a picture like this.
enter image description here

However I can get no where close to it. I have tried following other posts and adapting them which has allowed be to set the axis up correctly but I just cannot get the cubes the same way. Other than putting the location of each cube in manually is there a way to generate all cubes in one go. I don't even need as many cubes as there are in the attatched image, I just want a similar image.

I was able to do this with squares in the 2 dim plane in the following way:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}
 \begin{tikzpicture}[square/.style={regular polygon,regular polygon sides=4}]

% Coordinate axes
\begin{scope}[
  semithick,
  ->,
]
  \draw (0, 0) -- (0, 9.5);
  \draw (0, 0) -- (9.5, 0);

\end{scope}

\draw[node font=\small]
  \foreach \y in {0, ..., 9} {
    (0, \y) +(.25em, 0) -- ++(-.25em, 0)
    node[left] {$\y$}
  }      
\foreach \x in {1, ..., 9} {
    (\x,0)  +(0, .25em) -- ++(0, -.25em)
    node[below] {$\x$}    
} ;


\foreach \x in {0, ..., 9} {
 \foreach \y in {0, ..., 9} { 
\node[draw,square,inner sep=5pt,fill] at (\x+.5,\y+.5) {};                    
                } 
                }    
  \end{tikzpicture}
\end{document}

enter image description here

I would like to be able to do something similar, if possible.

Best Answer

Edit with closer output to the request, but still the angles needs adjustment (I will not do it)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3d,calc}

\begin{document}

\xdef\dist{0.25}
\xdef\hdist{0.1}
\xdef\ext{0.5}
\xdef\out{9.2}
 \begin{tikzpicture}[x={(-0.2cm,-0.4cm)}, y={(1cm,0cm)}, z={(0cm,1cm)},
     scale=0.8]


% Coordinate axes
\begin{scope}[canvas is xy plane at z=30,rotate around z=30, fill opacity=0.7]
  %\draw[->,thick] (0, 0,0) -- (0, 12.7,0)node[below]{\Large $\mathbf{y}$};
  %\draw[->,thick] (0, 0,0) -- (11.5, 0,0) node[left]{\Large $\mathbf{x}$};
  %\draw[->,thick] (0,0,0) -- (0,0,10.5)node[left]{\Large $\mathbf{z}$};

  \foreach \x in {0,1,...,9}{
  \foreach \y in {0,1, ..., 9} {
\foreach \z in {0,1,...,9}{
   \fill[draw=black,blue!75] (\x,\y,{\z+\dist}) --({\x+\dist},\y,{\z+\dist}) --({\x+\dist},{\y+\dist},{\z+\dist})--(\x,{\y+\dist},{\z+\dist})--cycle; 
   \fill[draw=black,brown!40!blue] (\x,\y,\z) --(\x,\y,{\z+\dist}) --({\x+\dist},\y,{\z+\dist})--({\x+\dist},\y,\z)--cycle; 
   \fill[draw=black,red!45] ({\x+\dist},\y,\z) --({\x+\dist},{\y+\dist},\z) --({\x+\dist},{\y+\dist},{\z+\dist})--({\x+\dist},\y,{\z+\dist})--cycle; 
 }}}



  \draw[thick]({0-\ext},{0-\ext},{0-\ext})--({0-\ext},{\out+\ext},{0-\ext})--({\out+\ext},{\out+\ext},{0-\ext})--({\out+\ext},{0-\ext},{0-\ext})--cycle;
  \draw[thick]({0-\ext},{0-\ext},{0-\ext})--({0-\ext},{0-\ext},{\out+\ext})--({\out+\ext},{0-\ext},{\out+\ext})--({\out+\ext},{0-\ext},{0-\ext})--cycle;
   \draw[thick]({0-\ext},{\out+\ext},{0-\ext})--({0-\ext},{\out+\ext},{\out+\ext})--({\out+\ext},{\out+\ext},{\out+\ext})--({\out+\ext},{\out+\ext},{0-\ext})--cycle;
   \draw[thick]({0-\ext},{0-\ext},{\out+\ext})--({0-\ext},{\out+\ext},{\out+\ext})--({\out+\ext},{\out+\ext},{\out+\ext})--({\out+\ext},{0-\ext},{\out+\ext})--cycle;
%\foreach \i in {1,...,9}
%{
% \draw[-,thin] (\i,\hdist,0)--(\i,-\hdist,0) node[left] {\i};
% \draw[-,thin] (0,\hdist,\i)--(0,-\hdist,\i) node[left] {\i};
%}



\end{scope}

  \end{tikzpicture}
\end{document}

enter image description here

Old Answer that just shows the basic code needed:

Here is a way:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3d,calc}

\begin{document}

\xdef\dist{0.2}
\xdef\hdist{0.1}
 \begin{tikzpicture}[x={(-0.2cm,-0.4cm)}, y={(1cm,0cm)}, z={(0cm,1cm)}, 
     scale=0.8,
     fill opacity=0.4,
     color={gray},bottom color=white,top color=black]

 \tikzset{xyplane/.style={canvas is xy plane at z=#1}}

% Coordinate axes
\begin{scope}[xyplane=0,rotate around z=28]
  \draw[->,thick] (0, 0,0) -- (0, 12.7,0)node[below]{\Large $\mathbf{y}$};
  \draw[->,thick] (0, 0,0) -- (11.5, 0,0) node[left]{\Large $\mathbf{x}$};
  \draw[->,thick] (0,0,0) -- (0,0,10.5)node[left]{\Large $\mathbf{z}$};
\foreach \i in {1,...,9}
{
 \draw[-,thin] (\i,\hdist,0)--(\i,-\hdist,0) node[left] {\i};
 \draw[-,thin] (0,\hdist,\i)--(0,-\hdist,\i) node[left] {\i};
}

\foreach \x in {0,1,...,9}{
  \foreach \y in {0,1, ..., 9} {
\foreach \z in {0,...,9}{
   \fill[draw=black,blue!75] (\x,\y,{\z+\dist}) --({\x+\dist},\y,{\z+\dist}) --({\x+\dist},{\y+\dist},{\z+\dist})--(\x,{\y+\dist},{\z+\dist})--cycle; 
   \fill[draw=black,brown!80] (\x,\y,\z) --(\x,\y,{\z+\dist}) --({\x+\dist},\y,{\z+\dist})--({\x+\dist},\y,\z)--cycle; 
   \fill[draw=black,red!45] ({\x+\dist},\y,\z) --({\x+\dist},{\y+\dist},\z) --({\x+\dist},{\y+\dist},{\z+\dist})--({\x+\dist},\y,{\z+\dist})--cycle; 
 }}}

\end{scope}

  \end{tikzpicture}
\end{document}

enter image description here