同时绘制多个地块

同时绘制多个地块

可以画出类似这样的图吗?我已经有图的顶部了。

在此处输入图片描述

梅威瑟:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[thick,font=\sffamily,line cap=round,>=stealth,node
    distance=1em]
 \draw [<->] (0,5) node[below left]{Loss} |- (7,0) node[below left]{Model complexity};
 \draw (0.8,5) to[bend right=50] node[pos=0.7,above right] {Training loss}(6,0.8);
 \draw (1.2,5) to[out=-80,in=180] (3,3) to[out=0,in=-155]
  node[pos=0.2,below right] {Generalization loss} (6,4);
 \draw[loosely dotted] (3,0) -- (3,5) node[above] (P) {Optimum};
 \path node[base left=of P] (U) {Underfitting}
    node[base right=of P] (O) {Overfitting};
 \draw[->] ([yshift=1ex]U.north east) -- ([yshift=1ex]U.north west);
 \draw[->] ([yshift=1ex]O.north west) -- ([yshift=1ex]O.north east);    
\end{tikzpicture}
\end{document}

答案1

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[>=stealth']\sffamily
  % main diagram
  \draw[<->] (0,5) |-
    node[rotate=90,above,pos=0.25]{model prediction error}
    node[below,pos=0.75]{model complexity}
    (8,0);
  \draw[<->] (0.3,4) .. controls +(2,-4) and +(-4,0.2) .. (7.8,0.6)
    node[below,font=\scriptsize]{training error};
  \draw[<->] (0.5,4.3) .. controls +(2,-3.8) and +(-2,-3.8) .. (7.8,4.3)
    node[above,align=center,font=\scriptsize]{prediciton error\\for new data};
  \draw[<->,gray] (7.5,0.8) -- node[rotate=90,above,font=\scriptsize]{optimism} +(0,2.5);
  % upper left
  \begin{scope}[shift={(0,5.5)}]
    \draw[<->] (0,1.5) |-
      node[rotate=90,above,pos=0.25,gray,font=\tiny]{happiness}
      node[below,pos=0.75,gray,font=\tiny](w1){wealth}
      (2.4,0);
    \draw[dotted] (w1) -- +(0,-5.2) node{\tiny$\circ$};
    \foreach \x/\y in {0.2/0.5,0.4/0.2,0.6/0.9,0.8/1.1,1.0/1.4,1.3/1.2,1.6/1.1,1.9/1.3} {
      \draw (\x,\y) node{\tiny x};
    }
    \draw[densely dashed,gray] (0.1,0.3) -- (1.8,1.5);
  \end{scope}
  % upper middle
  \begin{scope}[shift={(2.8,5.5)}]
    \draw[<->] (0,1.5) |-
      node[below,pos=0.75,gray,font=\tiny](w2){wealth}
      (2.4,0);
    \draw[dotted] (w2) -- +(0,-5.2) node{\tiny$\circ$};
    \foreach \x/\y in {0.2/0.5,0.4/0.2,0.6/0.9,0.8/1.1,1.0/1.4,1.3/1.2,1.6/1.1,1.9/1.3} {
      \draw (\x,\y) node{\tiny x};
    }
    \draw[densely dashed,gray] (0.3,0.2) .. controls +(0.2,0.6) and +(-1.8,0) .. (2.2,1.3);
  \end{scope}
  % upper right
  \begin{scope}[shift={(5.6,5.5)}]
    \draw[<->] (0,1.5) |-
      node[below,pos=0.75,gray,font=\tiny](w3){wealth}
      (2.4,0);
    \draw[dotted] (w3) -- +(0,-5.2) node{\tiny$\circ$};
    \foreach \x/\y[count=\i,remember=\x as \lastx,remember=\y as \lasty] in
      {0.2/0.5,0.4/0.2,0.6/0.9,0.8/1.1,1.0/1.4,1.3/1.2,1.6/1.1,1.9/1.3} {
      \draw (\x,\y) node{\tiny x};
      \ifnum\i>1\relax
      \draw[densely dashed,gray] (\lastx,\lasty) -- (\x,\y);
      \fi
    }
  \end{scope}
\end{tikzpicture}
\end{document}

相关内容