尝试绘制交叉验证

尝试绘制交叉验证

我想出了一个精彩的情节。我需要你帮我画出来:

在此处输入图片描述

梅威瑟:

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{matrix}
\begin{document}
  \begin{tikzpicture}
    \matrix (M) [matrix of nodes,
        nodes={minimum height = 7mm, minimum width = 2cm, outer sep=0, anchor=center, draw},
        column 1/.style={nodes={draw=none}, minimum width = 4cm},
        row sep=1mm, column sep=-\pgflinewidth, nodes in empty cells,
        e/.style={fill=yellow!10}
      ]
      {
        Experiment 1 & |[e]| & & & & \\
        Experiment 2 & & |[e]| & & & \\
        Experiment 3 & & & |[e]| & & \\
        Experiment 4 & & & & |[e]| & \\
        Experiment 5 & & & & & |[e]| \\
      };
      \draw (M-1-2.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Total number of datasets} (LT-|M-1-6.north east);
  \end{tikzpicture}
\end{document}

答案1

这样的绘图可以用许多不同的方式制作。对于这个特定的绘图,我建议使用循环\foreach而不是\matrix环境,因为它为制作条形图和单个块的轮廓提供了更大的灵活性。

scale=0.7下面的这个例子还可以通过改变环境中整张图片的 和scale=0.5图片右侧的 来轻松缩放scope。环境的第二个目的scope是定义其边界框的节点,以绘制将图片的两半连接在一起的箭头。

\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}

结果

相关内容