使用 Tikz 绘制多维数组

使用 Tikz 绘制多维数组

我想要绘制一个像附图这样的图,它实际上描述的是一个多维数组。多维数组示例

这是我的代码:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[x={(0.866cm,-0.5cm)}, y={(0.866cm,0.5cm)}, z={(0cm,1cm)}, scale=1.0,
    %Option for nice arrows
    >=stealth, %
    inner sep=0pt, outer sep=2pt,%
    axis/.style={thick,->},
    wave/.style={thick,color=#1,smooth},
    polaroid/.style={fill=black!60!white, opacity=0.3},
]
    % Colors
    \colorlet{darkgreen}{green!50!black}
    \colorlet{lightgreen}{green!80!black}
    \colorlet{darkred}{red!50!black}
    \colorlet{lightred}{red!80!black}

    % Frame
    \coordinate (O) at (0, 0, 0);


    \filldraw[polaroid] (0,-2,-1.5) -- (0,-2,1.5) -- (0,2,1.5) -- (0,2,-1.5) -- (0,-2,-1.5)
        node[below, sloped, near end]{Polaroid};%

            \draw[polaroid]   (12, -2,  -1.5) -- (12, -2,   1.5)  %Polarizing filter
        node [above, sloped,midway] {Polaroid} -- (12, 2, 1.5) -- (12, 2, -1.5) -- cycle;

       \end{tikzpicture}
\end{document}     

但是代码输出的结果与我需要的图表相差甚远。我有一张示例图像,从中我得到了灵感。在此处输入图片描述非常感谢您的帮助。

答案1

可能是这样的吗?

\documentclass[tikz,border=5]{standalone}
\begin{document} 
\begin{tikzpicture}[x=(15:.5cm), y=(90:.5cm), z=(330:.5cm), >=stealth]
\draw (0, 0, 0) -- (0, 0, 10) (4, 0, 0) -- (4, 0, 10);
\foreach \z in {0, 5, 10} \foreach \x in {0,...,3}
  \foreach \y [evaluate={\b=random(0, 1);}] in {0,...,3}
    \filldraw [fill=white] (\x, \y, \z) -- (\x+1, \y, \z) -- (\x+1, \y+1, \z) --
      (\x, \y+1, \z) -- cycle (\x+.5, \y+.5, \z) node [yslant=tan(15)] {\b};
\draw [dashed] (0, 4, 0) -- (0, 4, 10) (4, 4, 0) -- (4, 4, 10);
\draw [->] (0, 4.5, 0)  -- (4, 4.5, 0)   node [near end, above left] {Column};
\draw [->] (-.5, 4, 0)  -- (-.5, 0, 0)   node [midway, left] {Row};
\draw [->] (4, 4.5, 10) -- (4, 4.5, 2.5) node [near end, above right] {Channel};
\end{tikzpicture}%
\end{document}

在此处输入图片描述

答案2

这就是我想出的:

\documentclass{article}
\usepackage{tikz}
    \usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[x=0.5cm,y=0.5cm]
    \begin{scope}[rotate=130,]
        \draw[gray] (-4  ,-1.5) -- (6  ,3.5);
    \end{scope}
    \foreach \shift in {-5,0,5}
    {
        \foreach \x in {1,...,4}
        {
            \foreach \y in {1,...,4}
            {
                \begin{scope}[rotate=130,shift={(\shift,0.5*\shift)},]
                    \draw[fill=white] (\x,\y) rectangle (\x+1,\y+1);
                    \node at (\x+0.5,\y+0.5) {\pgfmathrnd\pgfmathparse{round(\pgfmathresult)}
                        \pgfmathprintnumber[precision=1]{\pgfmathresult}};
                \end{scope}
            }
        }
    }
    \begin{scope}[rotate=130,]
        \draw         (-4, 2.5) -- (6  ,7.5);
        \draw[dashed] (0 , 2.5) -- (10,7.5);
        \draw[dashed] (0 ,-1.5) -- (10,3.5) node[midway,anchor=south west] {Channel};
    \end{scope}
\end{tikzpicture}
\end{document}

数组中的单个条目是随机生成的,我这样做是为了不必亲自输入每个条目。结果如下所示大批

我希望剩下的部分很清楚:)

相关内容