如何在用 TikZ 制作的网格上显示标题?

如何在用 TikZ 制作的网格上显示标题?

我正在尝试创建一个马尔可夫图,如图 2 中 Dias & Vermunt 2007 所述。http://members.home.nl/jeroenvermunt/dias2006c.pdf

如下图所示:

在此处输入图片描述

到目前为止,我已经尝试使用网格进行 TiZ,它适用于渐变着色,但我似乎无法添加州名。我也尝试过使用表格,但结果看起来不太好(非常混乱,单元格大小不同)。

(我希望这做得正确,因为这是我第一次来这里!)

有谁知道如何添加标题名称并创建漂亮的地图?

多谢!


我不知道该如何回复评论。所以我会这样做。Ti 的矩阵库z 运行得很好(我确实看到了评论中发布的结果),但是当我将它扩展到 22*22 矩阵时,出现错误:

\hbox 过满-几乎所有段落中......

我尝试更改尺寸大小、最小宽度和文本宽度,但这没有帮助。你能解释一下这些测量值的含义以及如何解决这个问题吗?再次感谢您!


我需要几张相邻的马尔可夫图,但由于底部两张图的位置不同,对齐无法进行。有人知道如何解决这个问题吗? 在此处输入图片描述

\begin{figure}[tb]
\subcaptionbox{Cluster 1, $\pi_1 = 0.18$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=30mm, text width=28mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{   \&  AC  \&  CH  \&  DP  \&  HP  \&  IA  \&  LB  \&  LP  \&  NL  \&  SC  \&  show\_discount\_reminder    \&  show\_funnel\_campaign  \&  show\_recc  \&  show\_recp  \&  show\_upsell    \&  show\_wijnatlas     \&  WV  \&  XT  \\                                      
AC  \& |[fill=black!    2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  45  ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  37  ]|\& |[fill=black!  0   ]|\& |[fill=black!  3   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  5   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

XT  \& |[fill=black!    8   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  17  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  25  ]|\& |[fill=black!  0   ]|\& |[fill=black!  13  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 2, $\pi_2 = 0.16$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
%column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{       AC  \&  CH  \&  DP  \&  HP  \&  IA  \&  LB  \&  LP  \&  NL  \&  SC  \&  show\_discount\_reminder    \&  show\_funnel\_campaign  \&  show\_recc  \&  show\_recp  \&  show\_upsell    \&  show\_wijnatlas     \&  WV  \&  XT  \\                                      
     |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  79  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
     |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  14  ]|\& |[fill=black!  3   ]|\& |[fill=black!  0   ]|\& |[fill=black!  49  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  33  ]|\\                                                                    
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 3, $\pi_3 = 0.23$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=30mm, text width=28mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{AC \& |[fill=black!    2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  40  ]|\& |[fill=black!  10  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  40  ]|\& |[fill=black!  0   ]|\& |[fill=black!  7   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

XT  \& |[fill=black!    4   ]|\& |[fill=black!  0   ]|\& |[fill=black!  18  ]|\& |[fill=black!  19  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  25  ]|\& |[fill=black!  1   ]|\& |[fill=black!  20  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  9   ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 4, $\pi_4 = 0.13$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
%column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{    |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  71  ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  21  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

     |[fill=black!  3   ]|\& |[fill=black!  0   ]|\& |[fill=black!  16  ]|\& |[fill=black!  11  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  19  ]|\& |[fill=black!  0   ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  40  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 5, $\pi_5 = 0.17$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{AC \& |[fill=black!    1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  17  ]|\& |[fill=black!  4   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  76  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

XT  \& |[fill=black!    4   ]|\& |[fill=black!  0   ]|\& |[fill=black!  9   ]|\& |[fill=black!  28  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  29  ]|\& |[fill=black!  0   ]|\& |[fill=black!  13  ]|\& |[fill=black!  0   ]|\& |[fill=black!  3   ]|\& |[fill=black!  2   ]|\& |[fill=black!  0   ]|\& |[fill=black!  5   ]|\& |[fill=black!  8   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        
};
\end{tikzpicture}
}
\subcaptionbox{Cluster 6, $\pi_6 = 0.12$}{
\begin{tikzpicture}[font=\ttfamily, ampersand replacement=\&]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
%row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
%column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=right}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{    |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  40  ]|\& |[fill=black!  6   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  18  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  33  ]|\& |[fill=black!  0   ]|\& |[fill=black!  1   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                        

     |[fill=black!  7   ]|\& |[fill=black!  1   ]|\& |[fill=black!  8   ]|\& |[fill=black!  29  ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\& |[fill=black!  19  ]|\& |[fill=black!  0   ]|\& |[fill=black!  10  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  15  ]|\& |[fill=black!  0   ]|\& |[fill=black!  2   ]|\& |[fill=black!  7   ]|\& |[fill=black!  0   ]|\& |[fill=black!  0   ]|\\                                    
};
\end{tikzpicture}
}
\label{TP_userS6}
\caption{Transition probabilities of user data (ADJ) using MMM}
\end{figure}

答案1

您可以使用matrix

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[font=\sffamily\tiny]
\matrix (A) [nodes in empty cells,
        matrix of nodes,
        nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
        row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
        column 1/.style={nodes={draw=none, minimum width=12mm, text width=10mm, align=left}},
        column sep=-\pgflinewidth,
        row sep=-\pgflinewidth
        ]
{
& frontpage & news & tech \\
frontpage & |[fill=red]| & |[fill=orange]| & \\
news & & |[fill=red!70!black]| & \\
tech & & |[fill=yellow]| & |[fill=red!70!black]| \\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

更新:

22x22 矩阵的问题不在于其大小,而在于第一列节点的大小。在我之前的例子中,它们被定义为

    column 1/.style={nodes={draw=none, minimum width=12mm, text width=10mm, align=left}},

在这个大小下,它们可以容纳frontpage,但不能show\_discount\_reminer。如果您声明第 1 列节点足够长以应付这些长单词,则有关的所有消息overfull horizontal box都将消失。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{matrix}

\usepackage{lipsum}

\begin{document}
\lipsum[1]

\begin{figure}[tb]
\begin{tikzpicture}[font=\itshape]
\matrix (A) [nodes in empty cells,
matrix of nodes,
nodes={draw, minimum size=3mm, inner sep=0pt, outer sep=0pt, anchor=center},
row 1/.style={nodes={draw=none, rotate=90, anchor=west, inner xsep=1mm}},
column 1/.style={nodes={draw=none, minimum width=43mm, text width=40mm, align=left}},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth
]
{
&   AC &  ACRC  &   CH  &   DP    &   HP    &   IA    &   infl\_discount\_reminder &   infl\_funnel\_campaign    &   infl\_upsell  &   infl\_wijnatlas   &   LB    &   LP    &   NL    &   SC    &   show\_discount\_reminder  &   show\_funnel\_campaign    &   show\_recc    &   show\_recp &  show\_upsell  &   show\_wijnatlas   &   WV &  XT \\
AC & |[fill=black!    1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   39  ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   43  ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
ACRC  & |[fill=black! 40  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   20  ]|& |[fill=black!   20  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   20  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
CH    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   18  ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   30  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   22  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   22  ]|\\
DP    & |[fill=black! 6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   17  ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   52  ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
HP    & |[fill=black! 2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   7   ]|& |[fill=black!   49  ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   18  ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   13  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   3   ]|\\
IA    & |[fill=black! 3   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   14  ]|& |[fill=black!   14  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   18  ]|& |[fill=black!   1   ]|& |[fill=black!   25  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|\\
infl\_discount\_reminder  & |[fill=black! 2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   6   ]|& |[fill=black!   2   ]|& |[fill=black!   2   ]|& |[fill=black!   30  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   33  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
infl\_funnel\_campaign    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   27  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   48  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   22  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|\\
infl\_upsell  & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   64  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   36  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
infl\_wijnatlas   & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   64  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   27  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
LB    & |[fill=black! 5   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   13  ]|& |[fill=black!   22  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   32  ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   14  ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
LP    & |[fill=black! 6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   4   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   36  ]|& |[fill=black!   0   ]|& |[fill=black!   8   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   18  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   15  ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
NL    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|& |[fill=black!   5   ]|& |[fill=black!   81  ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
SC    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   2   ]|& |[fill=black!   1   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   4   ]|& |[fill=black!   0   ]|& |[fill=black!   47  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   23  ]|& |[fill=black!   0   ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
show\_discount\_reminder  & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   82  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   7   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|\\
show\_funnel\_campaign    & |[fill=black! 0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   81  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
show\_recc    & |[fill=black! 3   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   11  ]|& |[fill=black!   4   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   13  ]|& |[fill=black!   0   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   34  ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|\\
show\_recp & |[fill=black!    0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   50  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   50  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
show\_upsell  & |[fill=black! 1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   6   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   4   ]|& |[fill=black!   0   ]|& |[fill=black!   45  ]|& |[fill=black!   1   ]|& |[fill=black!   3   ]|& |[fill=black!   32  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   2   ]|\\
show\_wijnatlas   & |[fill=black! 10  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   12  ]|& |[fill=black!   3   ]|& |[fill=black!   1   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   43  ]|& |[fill=black!   0   ]|& |[fill=black!   7   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   21  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|\\
WV & |[fill=black!    0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   9   ]|& |[fill=black!   33  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   24  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   10  ]|& |[fill=black!   3   ]|\\
XT & |[fill=black!    5   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   15  ]|& |[fill=black!   19  ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|& |[fill=black!   25  ]|& |[fill=black!   0   ]|& |[fill=black!   15  ]|& |[fill=black!   0   ]|& |[fill=black!   1   ]|& |[fill=black!   14  ]|& |[fill=black!   0   ]|& |[fill=black!   3   ]|& |[fill=black!   2   ]|& |[fill=black!   0   ]|& |[fill=black!   0   ]|\\
};
\end{tikzpicture}
\caption{Markov map aggregated data (S=1).}
\end{figure}  
\end{document}

在此处输入图片描述

答案2

与您在问题中提出的方法类似的方法如下。我使用两个循环来标记列和行,然后使用一些循环\fill来标记选定的单元格,最后是网格。网格是最后一步绘制的,因此网格的线条覆盖了已填充单元格的边缘。

\documentclass [border=2mm]{standalone}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=0.4]
    % Put column headers
    \foreach \header [count=\c] in {Lorem, ipsum, dolor, sit, amet, consectetur, adipiscing, elit, Proin, vulputate, dignissim, odio, eu, euismod, sapien, sodales, eu, Curabitur, ipsum, nibh, dictum, eu} {
      \node[above] at (\c-0.5,22) {\rotatebox{90}{\small\sffamily\header}};
      }

    % Put row headers
    \foreach \header [count=\c] in {Lorem, ipsum, dolor, sit, amet, consectetur, adipiscing, elit, Proin, vulputate, dignissim, odio, eu, euismod, sapien, sodales, eu, Curabitur, ipsum, nibh, dictum, eu} {
      \node[left] at (0,22-\c+0.5) {\small\sffamily\header};
      }

    % Fill some squares
    \fill[black!10] (0,21) rectangle +(1,1); % Use relative coordinates for the rectangle size
    \fill[black!30] (1,20) rectangle +(1,1); % Use relative coordinates for the rectangle size

    % Finally, the grid
    \draw[black, very thin] (0,0) grid (22,22);
\end{tikzpicture}
\end{document}

结果:

结果

相关内容