# Trying to plot cross validation

I’ve come up with this wonderful plot. I need you to help me draw it:

MWE:

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

• What is the question? Jul 17 '19 at 16:12
• Guidance on how to draw it as it appears on the screen shot Jul 17 '19 at 16:14

A drawing like this can be made in many different ways. For this particular drawing I would suggest using a \foreach loop rather than \matrix environment, as it provides more flexibility for making the contours of the bars and individual blocks.

The example below can furthermore easily be scaled by changing the scale=0.7 of the whole picture and the scale=0.5 of the right-hand side of the picture in the scope environment. The secondary purpose of the scope environment is to define a node of its bounding box to draw the arrow that connects both halfs of the pictures together.

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


• It looks awesome! I’ll try to add some shadows to it! Jul 18 '19 at 14:10