Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created December 22, 2025 11:02
Show Gist options
  • Select an option

  • Save abikoushi/96e4a9702bcc0c1367af76e3180edae7 to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/96e4a9702bcc0c1367af76e3180edae7 to your computer and use it in GitHub Desktop.
A TikZ picture of HairEyeColor data as ALTO format
%ref:
%https://tex.stackexchange.com/questions/516073/how-to-draw-3d-matrix-using-tikz
%https://tikz.net/tikz-table/
%https://tikz.net/conv2d/
%
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{matrix,positioning}
\begin{document}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
rectangle,
draw=black,
fill=white,
align=center
},
minimum height=1.5em,
text depth=0.5ex,
text height=2ex,
nodes in empty cells,
%%
% every row/.style={
% nodes={fill=white}
%},
column 1/.style={
nodes={text width=4em, font=\bfseries}
},
row 1/.style={
nodes={
fill=gray,
text=white,
font=\bfseries
}
}
}
}
\begin{tikzpicture}
\matrix (male) [table, text width=6em]
{
& Brown & Blue & Hazel & Green\\
Black & 32 & 11 & 10 & 3\\
Brown & 53 & 50 & 25 & 15\\
Red & 10 & 10 & 7 & 7\\
Blond & 3 & 30 & 5 & 8\\
};
\matrix (female)[xshift=-3.5em, yshift=-3em] [table, text width=6em]
{
& Brown & Blue & Hazel & Green\\
Black & 36 & 9 & 5 & 2\\
Brown & 66 & 34 & 29 & 14\\
Red & 16 & 7 & 7 & 7\\
Blond & 4 & 64 & 5 & 8\\
};
\draw[thick,-stealth] ([xshift=1ex]male.south east) -- ([xshift=1ex]female.south east) node[midway, below,rotate=45, xshift=1ex] {sex};
\draw[thick,-stealth] ([yshift=-1ex]female.south west) -- ([yshift=-1ex]female.south east) node[midway,below] {eye};
\draw[thick,-stealth] ([xshift=-1ex]female.north west) -- ([xshift=-1ex]female.south west) node[midway,above,rotate=90] {hair};
\matrix(alto)[right = of female, xshift = 10ex] [table, text width=6em]
{
& Hair & Eye & Sex & Freq\\
0 & Black & Brown & Male & 32\\
1 & Brown & Brown & Male & 53\\
2 & Red & Brown & Male & 10\\
\vdots &\vdots & \vdots & \vdots &\vdots\\
30 & Red & Green & Female & 7\\
31 & Blond & Green & Female & 8\\
};
\draw[thick,-stealth] ([xshift=-1ex]alto.north west) -- ([xshift=-1ex]alto.south west) node[midway, above,rotate=90] {ALTO-index};
\draw[dashed, very thick, gray] (male-2-2) -- (alto-2-1);
\draw[dashed, very thick, gray] (female-4-5) -- (alto-6-1);
\draw[dashed, very thick, gray] (female-5-5) -- (alto-7-1);
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment