tikz grid of plots

With no captions:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata, backgrounds,calc,shapes}

\begin{document}
    \begin{figure}[ht]
    \centering
\tikzset{shorten >=1pt,
        node distance=1cm,
        font = \tiny,
        auto,%on grid
        state/.style = {shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt}
        }
\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state,  very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};
\end{tikzpicture}
\hfil
\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state, very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};

    \path[->,draw,thick]
    (a11) edge node {}(a12)
    (a11) edge node {}(a21);
\end{tikzpicture}

\vspace{11mm}
\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state, very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};

    \path[->,draw,thick]
    (a12) edge node {}(a22)
    (a21) edge node {}(a31);
\end{tikzpicture}
\hfil
\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state, very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};

    \path[->,draw,thick]
    (a12) edge node {}(a22)
    (a31) edge node {}(a32);
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

With caption and subcaptions:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata, backgrounds,calc,shapes}
\usepackage{subfig}

\begin{document}
    \begin{figure}[ht]
    \centering
\tikzset{shorten >=1pt,
        node distance=1cm,
        font = \tiny,
        auto,%on grid
        state/.style = {shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt}
        }
\subfloat[]{\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state,  very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};
\end{tikzpicture}}
\hfil
\subfloat[]{\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state, very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};

    \path[->,draw,thick]
    (a11) edge node {}(a12)
    (a11) edge node {}(a21);
\end{tikzpicture}}

\vspace{11mm}
\subfloat[]{\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state, very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};

    \path[->,draw,thick]
    (a12) edge node {}(a22)
    (a21) edge node {}(a31);
\end{tikzpicture}}
\hfil
\subfloat[]{\begin{tikzpicture}
    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state, very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};

    \path[->,draw,thick]
    (a12) edge node {}(a22)
    (a31) edge node {}(a32);
\end{tikzpicture}}
    \caption{my 2 x 2 images}
    \label{fig:fourimages}
\end{figure}
\end{document}

enter image description here

Off-topic: Code for your images can be significantly shortened if you employ TikZ library matrix. For example, the above second example can be written as:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\usepackage{subfig}

\begin{document}
    \begin{figure}[ht]
    \centering
\tikzset{M/.style = {matrix of math nodes,
                     ampersand replacement=\&,
                     column sep = 9mm,
                     row sep = 9mm,
                     nodes = {circle, draw, thick, minimum size=+3ex,
                              font=\tiny, anchor=center},
                     },  
every edge/.style =  {draw, ->, thick}
        }
\subfloat[]{
\begin{tikzpicture}
\matrix (m1) [M]
{
    a_{31}  \&  a_{32}  \\
    a_{21}  \&  a_{22}  \\
    a_{21}  \&  a_{22}  \\
};
\end{tikzpicture}}
\hfil
\subfloat[]{
\begin{tikzpicture}
\matrix (m2) [M]
{
    a_{31}  \&  a_{32}  \\
    a_{21}  \&  a_{22}  \\
    a_{21}  \&  a_{22}  \\
};
%
\path   (m2-1-1) edge (m2-1-2)
        (m2-1-1) edge (m2-2-1);
\end{tikzpicture}}

\vspace{11mm}
\subfloat[]{
\begin{tikzpicture}
\matrix (m3) [M]
{
    a_{31}  \&  a_{32}  \\
    a_{21}  \&  a_{22}  \\
    a_{21}  \&  a_{22}  \\
};
%
\path   (m3-1-2) edge (m3-2-2)
        (m3-2-1) edge (m3-3-1);
\end{tikzpicture}}
\hfil
\subfloat[]{
\begin{tikzpicture}
\matrix (m4) [M]
{
    a_{31}  \&  a_{32}  \\
    a_{21}  \&  a_{22}  \\
    a_{21}  \&  a_{22}  \\
};
\path   (m4-1-2) edge (m3-2-2)
        (m3-3-1) edge (m3-3-2);
\end{tikzpicture}}
    \caption{my 2 x 2 images}
    \label{fig:fourimages}
\end{figure}
\end{document}

Result is the same as before.


A solution with tabular:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,calc}
\begin{document}
\begin{tabular}{c@{\hspace{1cm}}c}%@{space between columns}
    \begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = \tiny,auto]%,on grid
    \tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]

    \node[state] (a31) {$a_{31}$};
    \node[state,above of=a31] (a21) {$a_{21}$};
    \node[state,  very thick, above of=a21] (a11) {$a_{11}$};

    \node[state,right of=a11] (a12) {$a_{12}$};
    \node[state,below of=a12] (a22) {$a_{22}$};
    \node[state,below of=a22] (a32) {$a_{32}$};
    \end{tikzpicture}
&
    \begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = \tiny,auto]%,on grid
        \tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]
        \node[state] (a31) {$a_{31}$};
        \node[state,above of=a31] (a21) {$a_{21}$};
        \node[state, very thick, above of=a21] (a11) {$a_{11}$};

        \node[state,right of=a11] (a12) {$a_{12}$};
        \node[state,below of=a12] (a22) {$a_{22}$};
        \node[state,below of=a22] (a32) {$a_{32}$};

        \path[->,draw,thick]
        (a11) edge node {}(a12)
        (a11) edge node {}(a21);
    \end{tikzpicture}\\[1cm]%space betweem rows 
    \begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = \tiny,auto]%,on grid
        \tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]

        \node[state] (a31) {$a_{31}$};
        \node[state,above of=a31] (a21) {$a_{21}$};
        \node[state, very thick, above of=a21] (a11) {$a_{11}$};

        \node[state,right of=a11] (a12) {$a_{12}$};
        \node[state,below of=a12] (a22) {$a_{22}$};
        \node[state,below of=a22] (a32) {$a_{32}$};

        \path[->,draw,thick]
        (a12) edge node {}(a22)
        (a21) edge node {}(a31);
    \end{tikzpicture}
&
     \begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = \tiny,auto]%,on grid
        \tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]

        \node[state] (a31) {$a_{31}$};
        \node[state,above of=a31] (a21) {$a_{21}$};
        \node[state, very thick, above of=a21] (a11) {$a_{11}$};

        \node[state,right of=a11] (a12) {$a_{12}$};
        \node[state,below of=a12] (a22) {$a_{22}$};
        \node[state,below of=a22] (a32) {$a_{32}$};

        \path[->,draw,thick]
        (a12) edge node {}(a22)
        (a31) edge node {}(a32);
\end{tikzpicture}\\
\end{tabular}
\end{document}

table of tikzpictures


This answer uses a matrix in two different way. Either a matrix of pics or using matrices to draw the sub diagrams. Unfortunately, one cannot nest matrices ... yet.

Matrix of pics: You can define a pic for the repeating things, and some simple macro to add the arrows. That way you do not have to repeat so many things. The pic can be defined in such a way that you only need to specify the arrows, e.g.

\pic{scheme={11->12,11->21}};

yields

enter image description here

The full picture is obtained with

    \matrix[column sep=1cm,row sep=1cm]{ 
        \pic{scheme}; & \pic{scheme={11->12,11->21}};\\
        \pic{scheme={12->22,21->31}}; & \pic{scheme={12->22,31->32}};\\
        };

enter image description here

The distance between the circle nodes is controlled by node distance, and the distance between the blocks by row sep and column sep, respectively.

This is the full code:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=1em,font = \tiny,auto,
    state/.style={shape=circle,draw,minimum width=+2ex,minimum
    height=+3ex,inner sep=+.2pt},arr/.style={->,thick,draw},
    pics/scheme/.style={code={%
    \path foreach \X [count=\mycolumn] in {-0.5,0.5}
    {foreach \Y [count=\myrow] in {1,0,-1}
    {(\X,\Y) node[state,
        line width={0.6pt+ifthenelse(\myrow+10*\mycolumn==11,1,0)*0.4pt}
        ] 
        (-\myrow-\mycolumn) 
    {$a_{\myrow\mycolumn}$} 
    }};
    \def\ArrDraw##1##2->##3##4;{
    \draw[arr] (-##1-##2) -- (-##3-##4);}
    \edef\tempnone{none}%
    \edef\temparg{#1}%
    \unless\ifx\temparg\tempnone
    \foreach \X in {#1}
    {\expandafter\ArrDraw\X;}
    \fi 
    }},pics/scheme/.default=none]
    \matrix[column sep=1cm,row sep=1cm]{ 
        \pic{scheme}; & \pic{scheme={11->12,11->21}};\\
        \pic{scheme={12->22,21->31}}; & \pic{scheme={12->22,31->32}};\\
        };
\end{tikzpicture}
\end{document}

Using matrices for the sub diagrams: Each of these diagrams is a simple matrix of nodes, which can be automatically filled. positioning allows you to position these matrices relative to each other.

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,matrix}

\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = \tiny,auto,
    state/.style={shape=circle,thick,draw,minimum width=+2ex,minimum
    height=+3ex,inner sep=+.2pt},arr/.style={->,very thick,draw},
    mymat/.style={matrix of nodes,nodes in empty cells,column sep=1em,
    row sep=1em,cells={nodes={state,execute at begin node={%
    $a_{\the\pgfmatrixcurrentrow\the\pgfmatrixcurrentcolumn}$}}}}]%,on grid
   \matrix[mymat]  (mat11) { |[very thick]| & \\ 
        & \\
        & \\};
   \matrix[mymat,right=of mat11] (mat12)  { |[very thick]| & \\ 
        & \\
        & \\};
   \draw[arr] (mat12-1-1) --    (mat12-1-2);
   \draw[arr] (mat12-1-1) --    (mat12-2-1);
   \matrix[mymat,below=of mat11] (mat21)  { |[very thick]| & \\ 
        & \\
        & \\};
   \draw[arr] (mat21-1-2) --    (mat21-2-2);
   \draw[arr] (mat21-2-1) --    (mat21-3-1);
   \matrix[mymat,right=of mat21] (mat22)  { |[very thick]| & \\ 
        & \\
        & \\};
   \draw[arr] (mat22-1-2) --    (mat22-2-2);
   \draw[arr] (mat22-3-1) --    (mat22-3-2);
\end{tikzpicture}
\end{document}

enter image description here

ADDENDUM: It is very easy to integrate captions into this.

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\usetikzlibrary{calc,positioning}
\tikzset{
    state/.style={shape=circle,draw,minimum width=+2ex,minimum
    height=+3ex,inner sep=+.2pt},arr/.style={->,thick,draw},
    pics/scheme/.style={code={%
    \begin{scope}[local bounding box=-bb]
    \path foreach \X [count=\mycolumn] in {-0.5,0.5}
      {foreach \Y [count=\myrow] in {1,0,-1}
      {(\X,\Y) node[state,
          line width={0.6pt+ifthenelse(\myrow+10*\mycolumn==11,1,0)*0.4pt}
          ] 
          (-\myrow-\mycolumn) 
      {$a_{\myrow\mycolumn}$} 
      }};
    \end{scope}
    \tikzset{ie86/.cd,#1}
    }},ie86/.cd,arrows/.code={\def\ArrDraw##1##2->##3##4;{
    \draw[arr] (-##1-##2) -- (-##3-##4);}
    \edef\tempnone{none}%
    \edef\temparg{#1}%
    \unless\ifx\temparg\tempnone
    \foreach \XX in {#1}
    {\expandafter\ArrDraw\XX;}
    \fi},arrows/.default=none,
    caption/.code={\path let \p1=($(-bb.east)-(-bb.west)$) in
     (-bb.south) node[below,text width=\x1,align=center,font=\normalsize] 
     {\begin{subfigure}{\x1}
     \caption{#1}
     \end{subfigure}};}}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[shorten >=1pt,node distance=1em,font = \tiny]
    \matrix[column sep=6mm,row sep=6mm]{ 
        \pic{scheme={caption={abc}}}; & 
        \pic{scheme={arrows={11->12,11->21},caption={}}};\\
        \pic{scheme={arrows={12->22,21->31},caption={blub}}}; &
        \pic{scheme={arrows={12->22,31->32},caption={bla}}};\\
        };
\end{tikzpicture}
\caption{Several graphs.}
\end{figure}
\end{document}

enter image description here

Tags:

Plot

Tikz Pgf