0

I need to make a figure using tikz package which would look similar to the example below (shapes of the objects in this example are not required - could be just rectangle as well):

enter image description here

3

2 Answers 2

2

Here's a slightly more succinct translation of your solution. The nodes are first created in a matrix of nodes. These are then joined using a few loops. Because a matrix of nodes names each node automatically, it isn't necessary to specify the names explicitly. By naming the matrix (M), the nodes are named according to the schema (M-<row>-<column>). I tried connecting them with graphs syntax, but graph syntax and matrices are not, it seems, a marriage made in heaven :(.

This also demonstrates a couple of different ways of customising all nodes in the matrix, all nodes in a row or individual nodes on-the-fly, and illustrates some other possible shapes suggested by the target image in the question.

\documentclass[border=10pt,multi,tikz,dvipsnames]{standalone}
\usetikzlibrary{positioning,matrix,arrows.meta,shapes.misc,shapes.symbols,shapes.geometric}
\begin{document}
\begin{tikzpicture}[>=Stealth, shape aspect=.25]
  \matrix (M) [matrix of nodes, every node/.style={font=\itshape, anchor=center, text centered, draw, text width=6.1em, minimum height=3em}, column sep=10mm, row sep=10mm, row 5/.append style={rounded rectangle}, row 4/.append style={rounded corners}, row 7/.append style={rounded corners}, row 3/.append style={shape border rotate=90, cylinder}]
  {
    && |[cylinder, shape border rotate=90]| {Imbalanced\\Data} && \\
    && |[rounded corners]| {Data\\Balancing} && \\
    {Balanced\\Data\textsubscript{1}} & {Balanced\\Data\textsubscript{2}} & |[draw=none]|$\cdots$ & {Balanced\\Data\textsubscript{K-1}} & {Balanced\\Data\textsubscript{K}} \\
    Modeling & Modeling & |[draw=none]|$\cdots$  &  Modeling & Modeling \\
    {Classifier\textsubscript{1}} & {Classifier\textsubscript{2}} & |[draw=none]|$\cdots$ & {Classifier\textsubscript{K-1}} & {Classifier\textsubscript{K}} \\
    & & |[rounded rectangle]| {Ensemble\\Classifying} & & \\
    & New Data & Classifying & & \\
    & & |[tape, tape bend top=none]| {Classification\\Results} & & \\
  };
  \coordinate [below=5mm of M-2-3] (p);
  \coordinate [above=5mm of M-6-3] (q);
  \foreach \i/\j in {M-1-3/M-2-3,M-6-3/M-7-3,M-7-3/M-8-3,M-7-2/M-7-3} \draw [->, thick] (\i) -- (\j);
  \foreach \i/\j in {3/4,4/5} \foreach \k in {1,2,4,5} \draw [->, thick] (M-\i-\k) -- (M-\j-\k);
  \draw [thick] (M-2-3) -- (p) \foreach \i in {1,2,4,5} {(M-5-\i) |- (q) (p) -- (p -| M-3-\i)};
  \draw [->, thick] \foreach \i in {1,2,4,5} {(p -| M-3-\i) edge  (M-3-\i)} (q) -- (M-6-3);
\end{tikzpicture}
\end{document}

concise code with fancy shapes

4
  • I have a problem with textsubscript, when applied to a number like: \textsubscript{2} it works, but with a letter like here: \textsubscript{K-1} the letter "K" is not subscripted, so the result looks like: DataK_{-1}
    – qerigan
    Sep 14, 2016 at 12:19
  • @qerigan As you can see, it works for me. You'd need to give a minimal example which can be used to reproduce the problem.
    – cfr
    Sep 14, 2016 at 12:38
  • I just copy-pased your solution and the \textsubscript just ignores the "K" letter in brackets. Perhaps some package is missing? Link to image example imgur.com/KRocWD5
    – qerigan
    Sep 14, 2016 at 12:52
  • I can't explain that. It seems very strange indeed. I suggest looking at the console output and in your logs for clues. Right now, I can't imagine how precisely this code could produce that output, so I need more information!
    – cfr
    Sep 14, 2016 at 16:43
2

If someone need something similar in future here is what I built.

\tikzstyle{box}=[rectangle, draw=black, rounded corners, text centered, anchor=north, text width=6.1em, minimum height=3em]
\tikzstyle{myarrow}=[->, thick, shorten >=1pt]
\tikzstyle{line}=[-, thick]

\begin{figure}
    \caption{Split schema}
    \label{fig:split}
    \begin{tikzpicture}[node distance=1cm]
        \node (ImbalancedData) [box] {$Imbalanced$\\$Data$};
        \node (DataBalancing) [box, below=0.5cm of ImbalancedData] {$Data$\\$Balancing$};
        \node (AuxNode01) [below=1.4cm of DataBalancing] {$\cdots$};
            \node (BalancedData2) [box, left=of AuxNode01] {$Balanced$\\$Data_{2}$};
            \node (BalancedData1) [box, left=of BalancedData2] {$Balanced$\\$Data_{1}$};
            \node (BalancedDataK-1) [box, right=of AuxNode01] {$Balanced$\\$Data_{K-1}$};
            \node (BalancedDataK) [box, right=of BalancedDataK-1] {$Balanced$\\$Data_{K}$};
        \node (AuxNode02) [below=1.4cm of AuxNode01] {$\cdots$};
            \node (Modeling2) [box, left=of AuxNode02] {$Modeling$};
            \node (Modeling1) [box, left=of Modeling2] {$Modeling$};
            \node (Modeling3) [box, right=of AuxNode02] {$Modeling$};
            \node (Modeling4) [box, right=of Modeling3] {$Modeling$};
        \node (AuxNode03) [below=1.4cm of AuxNode02] {$\cdots$};
            \node (Classifier2) [box, left=of AuxNode03] {$Classifier_{2}$};
            \node (Classifier1) [box, left=of Classifier2] {$Classifier_{1}$};
            \node (ClassifierK-1) [box, right=of AuxNode03] {$Classifier_{K-1}$};
            \node (ClassifierK) [box, right=of ClassifierK-1] {$Classifier_{K}$};
        \node (EnsembleClassifying) [box, below=1.4cm of AuxNode03] {$Ensemble$\\$Classifying$};
        \node (Classifying) [box, below=0.5 of EnsembleClassifying] {$Classifying$};
        \node (NewData) [box, left=1.5 of Classifying] {$New Data$};
        \node (ClassificationResults) [box, below=0.5 of Classifying] {$Classification$\\$Results$};

        \draw[myarrow] (ImbalancedData.south) -- (DataBalancing.north);
        \draw[myarrow] (DataBalancing.south) -- ++(0,-0.5) -| (BalancedData1.north);
        \draw[myarrow] (DataBalancing.south) -- ++(0,-0.5) -| (BalancedData2.north);
        \draw[myarrow] (DataBalancing.south) -- ++(0,-0.5) -| (BalancedDataK-1.north);
        \draw[myarrow] (DataBalancing.south) -- ++(0,-0.5) -| (BalancedDataK.north);
        \draw[myarrow] (BalancedData1.south) -- (Modeling1.north);
        \draw[myarrow] (BalancedData2.south) -- (Modeling2.north);
        \draw[myarrow] (BalancedDataK-1.south) -- (Modeling3.north);
        \draw[myarrow] (BalancedDataK.south) -- (Modeling4.north);
        \draw[myarrow] (Modeling1.south) -- (Classifier1.north);
        \draw[myarrow] (Modeling2.south) -- (Classifier2.north);
        \draw[myarrow] (Modeling3.south) -- (ClassifierK-1.north);
        \draw[myarrow] (Modeling4.south) -- (ClassifierK.north);
        \draw[myarrow] (Classifier1.south) -- ++(0,-0.5) -| (EnsembleClassifying.north);
        \draw[myarrow] (Classifier2.south) -- ++(0,-0.5) -| (EnsembleClassifying.north);
        \draw[myarrow] (ClassifierK-1.south) -- ++(0,-0.5) -| (EnsembleClassifying.north);
        \draw[myarrow] (ClassifierK.south) -- ++(0,-0.5) -| (EnsembleClassifying.north);
        \draw[myarrow] (EnsembleClassifying.south) -- (Classifying.north);
        \draw[myarrow] (NewData.east) -- (Classifying.west);
        \draw[myarrow] (Classifying.south) -- (ClassificationResults.north);
    \end{tikzpicture}
\end{figure}

enter image description here

3
  • 1
    It's not necessary to put the contents of the nodes inside $, you can remove them for normal text or if you want italic text you would be better off enclosing it with \textit{foo} as this will properly handle the spacings between letters.
    – Dai Bowen
    Sep 13, 2016 at 22:02
  • Nice. \tikzstyle is deprecated, though. tikzset{} is fortunately less typing and current ;).
    – cfr
    Sep 13, 2016 at 22:02
  • Since you've added this for future reference, you should also update the question title to reflect its content.
    – Holene
    Sep 14, 2016 at 4:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .