我正在寻找使用 JASA 论文中的 tikz 包重现图表:Moodie et al 2009 104(485):155-65。这是图:
节点和箭头似乎不太难生成。但我不知道如何放置时间刻度轴,以及如何将节点隔开以使其与时间刻度轴对齐。因此,为了让这个问题与更广泛的受众相关,如何在 tikz 图的底部放置 x 轴,并将节点与轴上的元素对齐?
以下是时间点 0 和 1 的起始示例:
\begin{tikzpicture}[line width=0.05cm]
\node [circle,draw] (h1) at (0,2) {$h$};
\node [circle,draw] (h2) at (2,2) {$h$};
\node [circle,draw] (b1) at (1.5,4) {$b$};
\begin{scope}[line width=.1cm,shorten >= 5pt, shorten <= 5pt]
\draw[->] (h1) -- (h2);
\draw[->] (h1) -- (b1);
\draw[->] (b1) -- (h2);
\end{scope}
\draw[help lines] (0,0) grid (5,5) ;
\end{tikzpicture}
我正在寻找可以添加到此代码中以获取时间轴(线、刻度线、数字和标题)。
答案1
Tikz 对重复性工作非常了解。以下是 Nicos 回答的简短版本:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%%plot the wt nodes and timeline ticks
\foreach \x in {0,1,2,3,6,9,12} {
\draw (\x ,0) node[anchor=north] {\x} -- (\x,0.1);
\node[draw,circle] (wt\x) at (\x,1) {wt};
};
%%plot the bt nodes and most edges
%%alternative for older tikz versions:
%\def\lastx{0}
%\foreach[remember =\x as \lastx] \x in {1,2,3,6,9,12} {
%%works for me with current version (3.0.0)
\foreach[remember =\x as \lastx (initially 0)] \x in {1,2,3,6,9,12} {
\node[draw,circle] (bf\lastx) at (0.5+\lastx,2) {bf};
\path[->] (wt\lastx) edge (wt\x);
\path[->] (wt\lastx) edge (bf\lastx);
\path[->] (bf\lastx) edge (wt\x);
}
%%plot the missing edges
\foreach[remember =\x as \lastx (initially 0)] \x in {1,2,3,6,9} {
\path[->] (bf\lastx) edge (bf\x);
}
\draw[->] (-.5,0) -- (12.5,0);
\end{tikzpicture}
\end{document}
编辑:根据添加替代版本这。
结果 :
答案2
对于如此简单的事情我会 KISS。
如果您像我一样是新手,那么越简单越好。
\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
[node distance=4mm and 1.75mm, bubbles/.style={draw,circle, minimum size=2em}]
% Bottom
\node[bubbles] (wt0) at (0, 0) {wt};
\node[bubbles] (wt1) at (1, 0) {wt};
\node[bubbles] (wt2) at (2, 0) {wt};
\node[bubbles] (wt3) at (3, 0) {wt};
\node[bubbles] (wt6) at (6, 0) {wt};
\node[bubbles] (wt9) at (9, 0) {wt};
\node[bubbles] (wt12) at (12, 0) {wt};
% Top
\node[bubbles] (bf0) [above right=of wt0] {bf};
\node[bubbles] (bf1) [above right=of wt1] {bf};
\node[bubbles] (bf2) [above right=of wt2] {bf};
\node[bubbles] (bf3) [above right=of wt3] {bf};
\node[bubbles] (bf6) [above right=of wt6] {bf};
\node[bubbles] (bf9) [above right=of wt9] {bf};
% Arrows
\draw [-latex,thick](wt0) -- (bf0);
\draw [-latex,thick](wt0) -- (wt1);
% And so on
% Timeline
\node at (0, -1) {0};
\node at (1, -1) {1};
\node at (2, -1) {2};
\node at (3, -1) {3};
\node at (6, -1) {6};
\node at (9, -1) {9};
\node at (12, -1) {12};
\end{tikzpicture}
\end{document}
解释:
- 将底部节点放在您想要的位置。您可以像我一样使用月份数。
- 将顶部节点相对于底部节点放置(这就是你放的图片中的样子)
- 箭头非常简单。
- 时间轴:节点与底部节点位于同一位置。