4

I want to create diagram like below.

enter image description here

Update: Mostly done.

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{colortbl,pgfplotstable}
\pgfplotstableread[header=false]{
 1     0     1
 0     3     0
 0     1     1
 3     0     0
 0     0     3
}\myB

\pgfplotstableread[header=false]{
    1     0     1
    1     1     0
    0     0     1
}\myA

\pgfplotstableread[header=false]{
 1     0     0     3     0
 0     3     1     0     0
 1     0     1     0     3
}\myD

\pgfplotstableread[header=false]{
1     0     1     1     1
1     1     2     1     0
1     1     1     1     1
1     0     1     1     2
2     0     1     0     1
}\myC


\pgfkeys{/mytable/.is family}
\pgfkeyssetvalue{/mytable/0}{gray}
\pgfkeyssetvalue{/mytable/1}{black}
\pgfkeyssetvalue{/mytable/3}{red}
\pgfkeyssetvalue{/mytable/2}{blue}

\def\imagetop#1{\vtop{\null\hbox{#1}}}

\begin{document}

\begin{tabular}{c@{\hskip 0.05cm}c@{\hskip 0.05cm}c@{\hskip 0.3cm}c}
$B$ & $A$ & $B^{T}$ & $\hat{C}$ \\
\imagetop{
\begin{tikzpicture}
\node {
\pgfplotstabletypeset[
postproc cell content/.style={/pgfplots/table/@cell content={%
        \cellcolor{\pgfkeysvalueof{/mytable/#1}}}},
every head row/.style={output empty row},]\myB
};
\end{tikzpicture}
} &
\imagetop{
\begin{tikzpicture}
\node {
\pgfplotstabletypeset[
postproc cell content/.style={/pgfplots/table/@cell content={%
        \cellcolor{\pgfkeysvalueof{/mytable/#1}}}},
every head row/.style={output empty row},]\myA
};
\end{tikzpicture}
} &
\imagetop{
\begin{tikzpicture}
\node {
    \pgfplotstabletypeset[
    postproc cell content/.style={/pgfplots/table/@cell content={%
            \cellcolor{\pgfkeysvalueof{/mytable/#1}}}},
    every head row/.style={output empty row},]\myD
};
\end{tikzpicture} 
} &
\imagetop{
\begin{tikzpicture}
\node {
\pgfplotstabletypeset[
postproc cell content/.style={/pgfplots/table/@cell content={%
        \cellcolor{\pgfkeysvalueof{/mytable/#1}}}},
every head row/.style={output empty row},]\myC
};
\end{tikzpicture} 
} \\
$p(w_{1} | z_{1})$ & $p(z_{1}, z_{2} | m)$ & $p(w_{2} | z_{2})$ & $p(w_{1}, 
w_{2} | m) $
\end{tabular}


\end{document}

Final version looks like this

enter image description here

seeker
  • 306

1 Answers1

8

Here is one way that you can generalize for your own needs

\documentclass{standalone}
\usepackage{colortbl,pgfplotstable}
\pgfplotstableread[header=false]{
 1     0     1
 0     3     0
 0     1     1
 3     0     0
 0     0     3
}\myB

\pgfkeys{/mytable/.is family}
\pgfkeyssetvalue{/mytable/0}{gray}
\pgfkeyssetvalue{/mytable/1}{black}
\pgfkeyssetvalue{/mytable/3}{red}
\pgfkeyssetvalue{/mytable/2}{blue}

\begin{document}
\pgfplotstabletypeset[
postproc cell content/.style={/pgfplots/table/@cell content={%
        \cellcolor{\pgfkeysvalueof{/mytable/#1}}}},
every head row/.style={output empty row},
]\myB
\end{document}

enter image description here

percusse
  • 157,807
  • can I nest these \pgfplotstabletypeset in atabular to get labels above and below. – seeker Jun 12 '16 at 21:12
  • 1
    @SivaPrasadVarma Not without some hacking but you can put them inside \nodes in a tikzpicture and label the nodes. – percusse Jun 12 '16 at 21:13
  • I got the nesting to work. Thanks. Now I just need to figure out how to align the short matrices in row 2 to align vertically. Please take a look at my updated post. – seeker Jun 12 '16 at 21:47
  • Figured it out throught TeX.SX. Thanks for helping out. Can you suggest any improvements – seeker Jun 12 '16 at 22:03