我对 KFold 进行了可视化,并希望使用“更花哨”的颜色。我的代码如下:
\documentclass[border=3mm]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{matrix,fit,positioning,decorations.pathreplacing}
\newcounter{Fold}
\edef\LstCol{"OliveGreen!60","MidnightBlue!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=OliveGreen!80,yshift=1cm,standard] (Trd) {Trainingsdaten};
% PROBLEM HERE
\node[fit=(M-1-2) (M-1-6),left color=OliveGreen!60, right color=MidnightBlue!50 ,yshift=1cm,standard] (Trd) {Trainingsdaten};
\node[right=0.5em of Trd,standard,fill=MidnightBlue!80,text width=4cm] (Ted) {Testdaten};
\node[fit=(Trd) (Ted),fill=gray!40,yshift=1cm,standard] (Ald) {Gesamter Datensatz};
\draw[thick,decorate] ([yshift=-3pt]M.north east) -- ([yshift=3pt]M.south east)
node[midway,right]{Finde Hyperparameter};
\node[anchor=north west,standard,text width=4cm,fill=Orange!80] at
(M.south-|Ted.west) (Ted2) {Testdaten};
\draw[thick,decorate] ([xshift=-2pt]Ted2.south west) -- ([xshift=-2pt]Ted2.north west)
node[midway,left]{Finale Evaluation};
\end{tikzpicture}
\end{document}
如您所见,节点“Trainingsdaten”中的颜色与矩阵中的其他颜色不相同。我该怎么办?
答案1
强制颜色使用相同的颜色模型,cmyk 或 rgb:
\documentclass[border=3mm]{standalone}
\usepackage[dvipsnames,rgb]{xcolor} %<-- or cmyk
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[left color=OliveGreen!60, right color=MidnightBlue!50] (Trd) at (0,0) {Trainingsdaten};
\node[fill=OliveGreen!60] (Trd) at(0,-1) {Trainingsdaten};
\end{tikzpicture}
\end{document}