修改结构

修改结构

附加的代码产生以下输出:

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,fit,positioning,decorations.pathreplacing} 
\newcounter{Fold}
\edef\LstCol{"green!50","blue!50"}
\begin{document}
\begin{tikzpicture}[font=\sffamily,
Fold/.style={/utils/exec=\stepcounter{Fold}
\pgfmathtruncatemacro{\itest}{ifthenelse(mod(\number\value{Fold},5)==int(1+\number\value{Fold}/5)
|| \number\value{Fold}==25,1,0)}
\pgfmathsetmacro{\mycol}{{\LstCol}[\itest]},fill=\mycol,draw,
node contents={Fold \pgfmathparse{int(mod(\number\value{Fold}-1,5)+1)}\pgfmathresult}
},
standard/.style={inner sep=0pt,align=center,draw,text height=1.25em,text depth=0.5em},
decoration={brace}]
 \matrix (M) [matrix of nodes,nodes in empty cells,nodes={Fold},
 row 1/.style={every node/.style={draw,fill=gray!30}},
 column 1/.style={every node/.style={}},
 column sep=1ex,row sep=1ex]
 { |[draw=none,fill=none]| & Fold 1 & Fold 2 & Fold 3 & Fold 4 & Fold 5 \\[1em]
   split 1 &  & & & & \\
   split 2 & &  & & & \\
   split 3 & & &  & & \\
   split 4 & & &  & & \\
   split 5 & & &  & & \\
 };
\node[fit=(M-1-2) (M-1-6),fill=green!50,yshift=1cm,standard] (Trd)  {Training data};
\node[right=0.5em of Trd,standard,fill=blue!50,text width=4cm] (Ted)  {Test data};
\node[fit=(Trd) (Ted),fill=gray!30,yshift=1cm,standard] (Ald)  {All data};
\draw[thick,decorate] ([yshift=-3pt]M.north east) -- ([yshift=3pt]M.south east)
node[midway,right]{Finding parameters};
\node[anchor=north west,standard,text width=4cm,fill=orange] at
(M.south-|Ted.west) (Ted2) {Test data};
\draw[thick,decorate] ([xshift=-2pt]Ted2.south west) -- ([xshift=-2pt]Ted2.north west)
node[midway,left]{Final evaluation};
\end{tikzpicture}
\end{document}

在此处输入图片描述

也许你可以帮我一下;我想把里面的部分,也就是折叠部分改成这样:

英

答案1

这是自动填充矩阵的棕褐色适应。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,decorations.pathreplacing} 
\newcounter{Vali}
\begin{document}
\begin{tikzpicture}[font=\sffamily,
 my cell/.style={minimum width=5em,text height=1.1em,text depth=0.3em,draw,anchor=center}, 
 sdiag/.style={row #1 column #1/.style={nodes={my cell,node contents=Validation,fill=gray!10}}},
 Vali/.style={/utils/exec=\stepcounter{Vali},my cell,draw=none,
    node contents=Validation score \#\number\value{Vali}},
 decoration=brace]
 \matrix(mat) [matrix of nodes,nodes in empty cells,
 nodes={my cell,node contents=Training},
 sdiag/.list={1,...,4},
 column 5/.style={every node/.style={Vali}},
 column sep=-\pgflinewidth,row sep=-\pgflinewidth]
 { & & & & \\
  & & & & \\
  & & & & \\
  & & & & \\
 };
 \foreach \X in {1,...,4}
 {\draw[decorate] (mat.west|-mat-\X-1.south) -- (mat.west|-mat-\X-1.north)
  node[midway,left]{Fold \X};}
 \draw[decorate] (mat-1-1.west|-mat.north) -- (mat-1-4.east|-mat.north)
 node[midway,above]{Data split in 4 partitions};
 \draw[decorate] (mat.north east) -- (mat.south east)
 node[midway,right,align=center]{Final score\\ average};
\end{tikzpicture}
\end{document}

在此处输入图片描述

您可以进一步实现自动化。当矩阵中的节点创建后,它们的位置将存储在\pgfmatrixcurrentrow和中\pgfmatrixcurrentcolumn。这可用于\ifnum语句。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,decorations.pathreplacing} 
\begin{document}
\begin{tikzpicture}[font=\sffamily,my cell/.style={
 minimum width=5em,text height=1.1em,text
 depth=0.3em,draw,anchor=center,
 execute at begin node={
  \ifnum\the\pgfmatrixcurrentcolumn=5
   Validation score \#\the\pgfmatrixcurrentrow
  \else
   \ifnum\the\pgfmatrixcurrentrow=\the\pgfmatrixcurrentcolumn
    Validation
   \else
    Training
   \fi
  \fi}, 
 /utils/exec={\ifnum\the\pgfmatrixcurrentrow=\the\pgfmatrixcurrentcolumn\relax
 \pgfkeysalso{/tikz/fill=gray!20}
 \fi
 \ifnum\the\pgfmatrixcurrentcolumn=5
 \pgfkeysalso{draw=none}
 \fi}
 }, decoration=brace]
 \matrix(mat) [matrix of nodes,nodes in empty cells,
 nodes={my cell}, column sep=-\pgflinewidth,row sep=-\pgflinewidth]
 { & & & & \\
  & & & & \\
  & & & & \\
  & & & & \\
 };
 \foreach \X in {1,...,4}
 {\draw[decorate] (mat.west|-mat-\X-1.south) -- (mat.west|-mat-\X-1.north)
  node[midway,left]{Fold \X};}
 \draw[decorate] (mat-1-1.west|-mat.north) -- (mat-1-4.east|-mat.north)
 node[midway,above]{Data split in 4 partitions};
 \draw[decorate] (mat.north east) -- (mat.south east)
 node[midway,right,align=center]{Final score\\ average};
\end{tikzpicture}
\end{document}

答案2

我只考虑你所画的部分(假设添加其他部分对你来说没有问题):

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathreplacing, 
                calligraphy}

\begin{document}
    \begin{tikzpicture}[
       font = \sffamily,
  BC/.style = {decorate,
        decoration={calligraphic brace, amplitude=3pt,
        pre =moveto, pre  length=1pt,
        post=moveto, post length=1pt,
        raise=2pt, mirror}, 
        thick,
        pen colour=black
        },
 box/.style = {draw, semithick, fill=#1,
        text width=5em, text depth=0.5ex, minimum height=4ex,
        align=center, inner sep=0pt, outer sep=0pt},
box/.default= none
                        ]
\foreach \x in {1,...,4} 
    \foreach \y in {1,...,4}
{
\ifnum\x=\y
    \node (n\x\y) [box=cyan!30] at (\x*5em,{(3-\y)*4ex}) {Validation};
\else
    \node (n\x\y) [box]         at (\x*5em,{(3-\y)*4ex}) {Training};
    \draw[BC]   (n1\y.north west) -- node[left=5pt] {Fold \y} (n1\y.south west);
\fi
}
\draw[BC]   (n41.north east)
    -- node[above=5pt,align=left] {Data split into 4 partitions} 
            (n11.north west);
\foreach \i in {4,...,1}
    \node (n4\i) [right] at (n4\i.east) {Validation score \# \i};
\draw[BC]   (n44.south east) --
    node[right=5pt,align=left] {Final\\ score\\ average} (n41.north east);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容