-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawmatrix.tikz.tex
64 lines (62 loc) · 2.89 KB
/
drawmatrix.tikz.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
% Based on http://tex.stackexchange.com/questions/123719/drawing-a-large-binary-matrix-as-colored-grid-in-tikz
\definecolor{neighbourstructurecolor}{RGB}{174,190,226}
\makeatletter
\tikzset{
blank color/.initial=white,
blank color/.get=\zerocol,
blank color/.store in=\zerocol,
detected color/.initial=neighbourstructurecolor,
detected color/.get=\onecol,
detected color/.store in=\onecol,
blocked color/.initial=black,
blocked color/.get=\twocol,
blocked color/.store in=\twocol,
alt color/.initial=blue,
alt color/.get=\threecol,
alt color/.store in=\threecol,
cell wd/.initial=1ex,
cell wd/.get=\cellwd,
cell wd/.store in=\cellwd,
cell ht/.initial=1ex,
cell ht/.get=\cellht,
cell ht/.store in=\cellht,
}
\newcommand{\drawmatrix}[2][]{
\medskip
\begin{tikzpicture}[#1]
\pgfplotstableforeachcolumn#2\as\col{
\pgfplotstableforeachcolumnelement{\col}\of#2\as\colcnt{%
\ifnum\colcnt=0
\draw[draw=gray,very thin,fill=\zerocol]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\fi
\ifnum\colcnt=1
\draw[draw=gray,very thin,fill=\onecol]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\fi
\ifnum\colcnt=2
\fill[pattern=dots]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\fi
\ifnum\colcnt=3
\draw[draw=gray,very thin,fill=\threecol]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\fi
\ifnum\colcnt=5
\draw[draw=gray,very thin,fill=\onecol]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\node[rectangle, minimum width=\cellwd, minimum height=\cellht] at ($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) + (\cellwd/2,\cellht/2) $) {A};
\fi
\ifnum\colcnt=6
\draw[draw=gray,very thin,fill=\onecol]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\node[rectangle, minimum width=\cellwd, minimum height=\cellht] at ($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) + (\cellwd/2,\cellht/2) $) {B};
\fi
\ifnum\colcnt=7
\draw[draw=gray,very thin,fill=\onecol]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\node[rectangle, minimum width=\cellwd, minimum height=\cellht] at ($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) + (\cellwd/2,\cellht/2) $) {C};
\fi
\ifnum\colcnt=9
\draw[draw=gray,very thin,fill=\zerocol]($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) $) rectangle+(\cellwd,\cellht);
\node[rectangle, text=red] at ($ -\pgfplotstablerow*(0,\cellht) + \col*(\cellwd,0) + (\cellwd/2,\cellht/2) $) {$\mathlarger{\mathlarger{\mathlarger{\mathlarger\times}}}$};
\fi
}
}
\end{tikzpicture}
\medskip
}
\makeatother