尝试绘制层次结构

尝试绘制层次结构

你能帮我完成这两幅画吗?

第一的:

在此处输入图片描述

第二:

在此处输入图片描述

mwe(取自这里

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{positioning,arrows.meta}
\begin{document}
  \begin{tikzpicture}[node distance=0mm,minimum height=1cm,outer sep=3mm,scale=0.7,>=Latex,font=\footnotesize,
  indication/.style={minimum height=0cm,outer sep=0mm},
  oneblock/.style={transform shape,minimum width=1cm,draw},
  fullset/.style={transform shape,minimum width=10cm,draw}]
    % left part of picture
    \node[fullset,anchor=west] at (0,0) (A) {};
    \node[above=of A.north,indication] (ATXT) {TRAINING SET};
    \node[oneblock,minimum width=2cm,anchor=west,right=of A,fill=lightgray,outer sep=0mm] (A1) {};
    \path (ATXT) -| (A1) node[midway] {TEST SET};
    \node[fullset,anchor=west] at (0,-4) (B) {};
    \foreach \x in {0,1,...,9}
    {
        \draw (B.west) +(\x,0) node[oneblock,anchor=west,draw] {};
    }
    \draw[->] (A) -- (B) node[midway,fill=white,indication] {divide into 10 folds of equal size};

    % right part of picture
    \begin{scope}[xshift=15cm,scale=0.5,local bounding box=rightside box]
    \foreach \x in {0,1}
    {
        \foreach \y in {0,1,...,4}
        {
            \draw (\x*11,0) +(0,-\y*2) node[fullset,anchor=west] {};
            \draw (\x*11,0) +(\x*5+\y,-\y*2) node[oneblock,draw,anchor=west,fill=lightgray] {};
        }
    }
    \coordinate (R) at (rightside box.west);
    \end{scope}

    % connecting arrow
    \draw[->] (B.east) -- +(2.5,0) node[below,align=center,indication] {run experiments\\using 10 different\\partitionings} |- (R);
  \end{tikzpicture}
\end{document}

对于树:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees,calc}

\begin{document}
\begin{tikzpicture}[
every node/.style={draw, rectangle, fill=gray!20},
edge from parent path={
(\tikzparentnode) |-   % Start from parent
($(\tikzparentnode)!0.5!(\tikzchildnode)$) -| % make an ortho line to mid point
(\tikzchildnode)}]                            % make another ortho to the target

  \node {root}
  child {node {left}}
  child {node {right}
    child {node {child}}
    child {node {child}}
  };
\end{tikzpicture}
\end{document}

答案1

第一张图片:

在此处输入图片描述

\documentclass[border=7pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
                positioning}
\usepackage{siunitx}

\begin{document}
    \begin{forest}
for tree = {
    draw,
    minimum height=4ex,
    text depth=0.5ex,
    anchor=north,
    inner sep=1mm,
    tw/.style = {text width=#1*1.3 em},
    text centered,
    %
    s sep=1em,
    l sep=8ex,
    edge={thick,-{Triangle[angle=60:2pt 3]}},
    edge path={
    \noexpand\path[\forestoption{edge}]
      (!u.south) -- (.north);
                },
            }
[Dataset \SI{100}{\%}, tw=10,
    [Training set  \SI{80}{\%}, minimum width=8em,
        [Parameter tuning set \SI{90}{\%},tw=9]
        [,tw=1,label=right:Test set \SI{20}{\%}]
    ]
    [,tw=2,label=right:Validation set \SI{10}{\%}]
] 
    \end{forest}
\end{document}

第二张图片:

在此处输入图片描述

\documentclass[border=7pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
                chains,
                fit,
                positioning}
\usepackage{siunitx}
\tikzset{
  node distance = 2mm and 0mm,
    start chain = A going below,
    wbox/.style = {draw, text width=8*1.3 em, inner sep=1mm,
                   on chain, node contents={}},
    gbox/.style = {draw, fill=lightgray, text width=1em, 
                   inner xsep=0mm, inner ysep=1mm, 
                   node contents={}},
every label/.append style = {font=\footnotesize}
        }
\begin{document}
    \begin{forest}
for tree = {
    draw,
    minimum height=4ex,
    text depth=0.5ex,
    anchor=north,
    inner sep=1mm,
    tw/.style = {text width=#1*1.3 em},
    text centered,
    %
    s sep=1em,
    l sep=8ex,
    edge={thick,-{Triangle[angle=60:2pt 3]}},
    edge path={
    \noexpand\path[\forestoption{edge}]
      (!u.south) -- (.north);
                },
            }
[Dataset \SI{100}{\%}, tw=10,
    [Training set  \SI{80}{\%}, tw=8, name=DS]
    [,tw=2,label=right:Validation set \SI{20}{\%}]
] 
\node [wbox, below=4mm of DS, label=left:1];    % A-1
\foreach \i [count=\j from 2] in {2,3,4,n}
{
\ifnum\j=4
\node [wbox, draw=none, label={[yshift=0.8ex]center:$\vdots$}]; % A-5
\else
\node [wbox, label=left:$\i$]; % A-2, ..., A-4
\fi
}
\foreach \i [count=\j from 0]in {1,2,3,5}
{
\ifnum\i=5
\node [gbox, left =of A-\i.east];
\else
\node [gbox, right=\j em of A-\i.west];
\fi
}    
\node (n6)  [draw=cyan, rounded corners, dashed, 
             inner xsep=1em, xshift=-0.5em, 
             fit=(A-1) (A-5),
             label=right:text] {};
\draw[-{Triangle[angle=60:2pt 3]}] (DS) -- (n6);
\end{forest}
\end{document}

相关内容