【问题标题】:Create data partition figure创建数据分区图
【发布时间】:2019-08-05 09:13:29
【问题描述】:

我想在 Latex 中创建一个与此类似的图形(但在块中也有百分比):

我设法做到了这一点(MWE):


\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{arrows,calc,positioning}
\usepackage{xcolor}


\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%

\begin{document}
\tikzset{
    train/.style={
        text=black,
        draw,
        minimum height=1cm,
        minimum width=7cm,
        left color=orange, right color=orange!30!white,shading angle=90},
    val/.style={
        draw,
        text=black,
        minimum height=1cm,
        minimum width=2cm,
        left color=orange!30!white, right color=green!30!white,shading angle=90},
    test/.style={
        draw,
        text=black,
        fill=cyan,
        minimum height=1cm,
        minimum width=1cm}}
\begin{tikzpicture}[thin,black]
\path
(0,0)       node[train] (N) {70\%}
++(0:4.5)     node[val] (C) {20\%}
+(0:2)    node[test] (O) {10\%};

\end{tikzpicture}  
\end{document}

这会导致:

显然,带有训练、验证和测试描述的箭头仍然缺失,我无法找到如何创建它。

我该怎么办?

谢谢!

【问题讨论】:

    标签: plot latex tikz pgf


    【解决方案1】:

    通常我会推荐 decorations.pathreplacing 库来为 tikz 图片添加大花括号,但在这种特殊的情况下,绘制一些圆角路径可能会更容易:

    \documentclass{article}
    \usepackage[latin1]{inputenc}
    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}
    \usetikzlibrary{arrows,calc,positioning}
    \usepackage{xcolor}
    
    
    \usepackage{verbatim}
    \usepackage[active,tightpage]{preview}
    \PreviewEnvironment{tikzpicture}
    \setlength\PreviewBorder{5pt}%
    
    \begin{document}
    \tikzset{
        train/.style={
            text=black,
            draw,
            minimum height=1cm,
            minimum width=7cm,
            left color=orange, right color=orange!30!white,shading angle=90},
        val/.style={
            draw,
            text=black,
            minimum height=1cm,
            minimum width=2cm,
            left color=orange!30!white, right color=green!30!white,shading angle=90},
        test/.style={
            draw,
            text=black,
            fill=cyan,
            minimum height=1cm,
            minimum width=1cm}}
    \begin{tikzpicture}[thin,black]
    \path
    (0,0)       node[train] (N) {70\%}
    ++(0:4.5)     node[val] (C) {20\%}
    +(0:2)    node[test] (O) {10\%};
    \draw[->,rounded corners=1mm] (-3.5,0.6) |- (0,1) -- ++(0,0.5);
    \draw[->,rounded corners=1mm] (3.5,0.6) |- (0,1) -- ++(0,0.5);
    \draw[->,rounded corners=1mm] (3.5,0.6) |- (4.5,1) -- ++(0,0.5);
    \draw[->,rounded corners=1mm] (5.5,0.6) |- (4.5,1) -- ++(0,0.5);
    \draw[->,rounded corners=1mm] (6,0.6) |- (6.5,1) -- ++(0,0.5);
    \draw[->,rounded corners=1mm] (7,0.6) |- (6.5,1) -- ++(0,0.5);
    \node at (0,1.7) {Train};
    \node at (4.5,1.7) {Validation};
    \node at (6.5,1.7) {Test};
    \end{tikzpicture}  
    \end{document}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多