我怎样才能生成类似该图的线图?

我怎样才能生成类似该图的线图?

我正在尝试使用 Tikz 包绘制左侧的图形。有人有模板可以分享吗?非常感谢,

在此处输入图片描述

答案1

为了制作左侧图形,我们可以从图像中定义一个命令来制作主体图标,对于线条,使用arrowarrow.meta库。

输入

\documentclass[border = 5pt]{standalone}

\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{positioning,arrows, arrows.meta}

\newcommand{\body}{
    \includegraphics[scale=0.036]{body.png}
}

\begin{document}
    
    \begin{tikzpicture}[every node/.style={scale=0.3}]
        % Drawing the main axis with 10 body icons
        \draw[<->] (0,6) |- (6.5,0);
        \foreach \b\n in {0.5/J,1/I,1.5/H,2/G,2.5/F,3/E,3.5/D,4/C,4.5/B,5/A}{
            \node[left=-0.03] (marks) at (0,\b){\rule{10pt}{1pt}};
            \node[left=0.15] (bodies) at (0,\b){\body};
            \node[left=0.35] at (0,\b){\textbf{\textsf{UC-\n}}};
        }
        % Drawing the dotted lines
        \foreach \l\s in {1/entry,5.5/exit}{
            \draw[densely dotted, cyan] (\l,0) node[below=0.05,black,scale=1.3]{Study \s} -- (\l,6);
        }
        % Drawing the horizontal marks
        \foreach \t\n\nn in {1.5/2/1, 2/4/2, 2.5/6/3, 3/8/4, 3.5/10/5, 4/12/6, 4.5/14/7, 5/16/8}{
            \node[rotate = -90] (marks) at (\t,-0.05){\rule{10pt}{1pt}};
            \node[scale=1.5, below, xshift=5pt] at (marks.south east){$\mathrm{\n^{\mathbf{t_{\nn}}}}$};
        }
        % Drawing the lines
        % Left truncated
        \draw[{Ellipse[gray]}-{Ellipse[cyan]}, red, dash pattern = on 2pt off 0.5pt] (0.01,1.5) -- (0.95,1.5) node[midway, above=0.05, black]{Left truncated};
        % T = 4
        \draw[{Ellipse[gray]}-{Ellipse[cyan]}, red] (1.01,0.5) -- (2,0.5) node[midway, above = 0.05, black]{$T=4$};
        % T = 10 (Lost)
        \draw[{Circle[gray]}-{Rays[black]}, red] (2,1) -- (4.5,1) node[midway, above=0.05, black]{$T=10$} node[right,black]{Lost};
        % T = 10
        \draw[{Circle[gray]}-{Rays[black]}, red] (3,2) -- (5.56,2) node[midway, above=0.05, black]{$T=10$};
        % T = 5.5
        \draw[{Ellipse[gray]}-{Rays[black]}, red] (1.5,2.5) -- (3,2.5) node[midway, above=0.05,black]{$T=5.5$} node[right,black]{Withdrawn};
        % T = 18
        \draw[{Circle[gray]}-{Rays[black]}, red] (1,3) -- (6,3) node[midway, above=0.05,black]{$T = 18$} node[midway, below=0.05, black]{Event occurred after study period ends};
        % T = 6
        \draw[{Ellipse[gray]}-{Ellipse[cyan]}, red] (2,3.5) -- (4.5,3.5) node[midway, above=0.05, black]{$T = 6$};
        % T = 8
        \draw[{Ellipse[gray]}-{Ellipse[cyan]}, red] (1,4) -- (2.75,4) node[midway, above=0.05, black]{$T = 8$};
        % T = 4 (Withdrawn)
        \draw[{Ellipse[gray]}-{Rays[black]}, red] (1.5,4.5) -- (2.5,4.5) node[midway, above=0.05,black]{$T=4$} node[right,black]{Withdrawn};
        % T = 8
        \draw[{Circle[gray]}-{Circle[cyan]}, red] (1,5) -- (3,5) node[midway, above=0.05, black]{$T = 8$};
        % Right Truncated
        \draw[{Ellipse[gray]}-{Ellipse[cyan]}, red, dash pattern = on 2pt off 0.5pt] (5.5,1.5) -- (6.5,1.5) node[midway, above=0.05, black]{Right truncated};
    \end{tikzpicture}
    
\end{document}

输出

在此处输入图片描述

我设置了命令来根据此图像制作身体:

在此处输入图片描述

您可以使用Z 来绘制这个身体图标,但如果您不想做额外的工作,您也可以使用图像。

相关内容