Tikz:绘制带有文本规范和颜色的网格矩阵

Tikz:绘制带有文本规范和颜色的网格矩阵

我是 Tikz 新手,我正在尝试绘制一个非常具体的图形。它包含几个功能,以我有限的知识我无法做到。它是一种网格类型的绘图,带有一些文本规范,如附图所示,在此处输入图片描述。这只是我想制作的一系列绘图的第一步,即添加动画。查看其他帖子似乎可以使用 tikz 或 pgfplot 来完成,但我不确定哪一个更适合稍后添加一些动画,例如网格填充。

我目前拥有的代码如下,尝试使用 tikz 绘制网格作为第一步,但它看起来相当繁琐。

 \documentclass[24point]{article}
    \usepackage{tikz}
    
    \begin{document}
    
    \begin{tikzpicture}[every node/.style={minimum size=.5cm-\pgflinewidth, outer sep=0pt}]
     \draw[thin, step=0.5cm,color=black] (0,3) grid (6,0.5);
    \node[] at (+0.25,+1.25) {0};
    \node[] at (+0.75,+1.25) {0};
    \node[] at (+1.25,+1.25) {0};
    \node[] at (+1.75,+1.25) {0};
    \node[fill=lightgray] at (+2.25,+1.25) {1};
    \node[fill=lightgray] at (+2.75,+1.25) {1};
    \node[fill=lightgray] at (+3.25,+1.25) {1};
    \node[fill=lightgray] at (+3.75,+1.25) {1};
    \node[fill=gray] at (+4.25,+1.25) {1};
    \node[] at (+4.75,+1.25) {0};
    \node[] at (+5.25,+1.25) {0};
    \node[] at (+5.75,+1.25) {0};
    \node[] at (+0.25,+1.75) {0};
    \node[] at (+0.75,+1.75) {0};
    \node[] at (+1.25,+1.75) {0};
    \node[] at (+1.75,+1.75) {0};
    \node[fill=lightgray] at (+2.25,+1.75) {1};
    \node[] at (+2.75,+1.75) {0};
    \node[] at (+3.25,+1.75) {0};
    \node[] at (+3.75,+1.75) {0};
    \node[] at (+4.25,+1.75) {0};
    \node[] at (+4.75,+1.75) {0};
    \node[] at (+5.25,+1.75) {0};
    \node[] at (+5.75,+1.75) {0};
    \node[] at (+0.25,+2.75) {1};
    \node[] at (+0.75,+2.75) {2};
   \node[] at (+1.25,+2.75) {3};
   \node[] at (+1.75,+2.75) {4};
   \node[] at (+2.25,+2.75) {5};
   \node[] at (+2.75,+2.75) {6};
   \node[] at (+3.25,+2.75) {7};
   \node[] at (+3.75,+2.75) {8};
   \node[] at (+4.25,+2.75) {9};
   \node[] at (+4.75,+2.75) {10};
   \node[] at (+5.25,+2.75) {11};
   \node[] at (+5.75,+2.75) {12};
    \end{tikzpicture}
        
    
    \end{document}

我将非常感激任何可以遵循的指示。

编辑 以下代码是我使用矩阵 tikz 编写的版本。不过,我需要在行之间添加更多空间、行之间的双线以及侧面的垂直文本。我从中摘取了部分代码填充节点矩阵的最简单方法是什么?

    \documentclass[24point]{article}
            \usepackage{tikz}
            
            \begin{document}
    
     \tikzstyle{matrici}=[
           matrix of math nodes, 
          nodes in empty cells,
          column sep=-\pgflinewidth, % to avoid double borders in contiguous cells
       nodes={
        draw, 
       align=center, 
      inner sep=0pt, 
        text width=0.5cm, 
        minimum height=0.5cm
    }
    ]
    
         \begin{tikzpicture} 
        
       
        \matrix[matrici, 
         row 1/.style={nodes={draw=none, fill=none}},
row 2/.style={nodes={draw=none, fill=none}},
row 3/.style={nodes={draw=none, fill=none}},
row 2 column 1/.style={nodes={font=\small}},
row 2 column 2/.style={nodes={font=\small}},
row 2 column 3/.style={nodes={font=\small}},
row 2 column 4/.style={nodes={font=\small}},
row 2 column 5/.style={nodes={font=\small}},
row 2 column 6/.style={nodes={font=\small}},
row 2 column 7/.style={nodes={font=\small}},
row 2 column 8/.style={nodes={font=\small}},
row 2 column 9/.style={nodes={font=\small}},
row 2 column 10/.style={nodes={font=\small}},
row 2 column 11/.style={nodes={font=\small}},
row 2 column 12/.style={nodes={font=\small}},
row 3 column 1/.style={nodes={font=\small}},
row 3 column 2/.style={nodes={font=\small}},
row 3 column 3/.style={nodes={font=\small}},
row 3 column 4/.style={nodes={font=\small}},
row 3 column 5/.style={nodes={font=\small}},
row 3 column 6/.style={nodes={font=\small}},
row 3 column 7/.style={nodes={font=\small}},
row 3 column 8/.style={nodes={font=\small}},
row 3 column 9/.style={nodes={font=\small}},
row 3 column 10/.style={nodes={font=\small}},
row 3 column 11/.style={nodes={font=\small}},
row 3 column 12/.style={nodes={font=\small}},
row 2 column 5/.style={nodes={fill=gray!20, font=\small}},
row 3 column 5/.style={nodes={fill=gray!30, font=\small}},
row 3 column 6/.style={nodes={fill=gray!30, font=\small}},
row 3 column 7/.style={nodes={fill=gray!30, font=\small}},
row 3 column 8/.style={nodes={fill=gray!30, font=\small}},
row 3 column 9/.style={nodes={fill=gray!20, font=\small}},
]  
(X)  
{1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
0 &  0   & 0  & 0  & 1   &  0 & 0   & 0  & 0  &  0  &  0   & 0 \\
0 & 0   & 0  & 0  & 1   &  1 & 1   & 1  & 1  &  0  &  0   & 0 \\
&&&&&&&&&&&\\
};

\draw[->, thick] (-0.80,-1.6) -- (1,-1.6);

\draw [densely dashed] (-1,-1.1) -- (-1,-1.7);

\draw [densely dashed] (1.25,-1.1) -- (1.25,-1.7);
\end{tikzpicture}  
        
        \end{tikzpicture}   
    \end{document}

相关内容