我想用 tikz 重现底部的图形。我绘制了图形依赖图,我想在上面添加一个时间序列,就像你看到的那样。
正如您所看到的,我需要图中的圆(节点)t_i 与轴上的时间 t_i 之间完美对齐。
下面是图形依赖关系的 tikz 代码:
\begin{tikzpicture}[main/.style={circle, minimum size = 10mm, thick, draw =black!80, node distance = 10mm},
box/.style={rectangle, draw=black!100}]
% put nodes
\node[main,draw =red!80] (t1) {$t_i$};
\node[main] (t2) [right= 3cm of t1] {$t_{i+1}$};
\node[main] (t3) [right= of t2] {$t_{i+2}$};
\node[main] (tn) [right= of t3] {$t_{n}$};
\node[main] (t) [left= 3cm of t1] {$t_{i-1}$};
\node[main] (tt) [left= of t] {$t_{i-2}$};
\node[main] (t0) [left= of tt] {$t_{0}$};
% make path ...
\path (t3) -- node[auto=false]{\ldots} (tn);
\path (tt) -- node[auto=false]{\ldots} (t0);
% draw arrows
\draw [->,dashed] (t1) to [out=45,in=165] node [midway, above] {$P(k=n|\lambda=1)$} (tn);
\draw [->,dashed] (t1) to [out=-10,in=-155] node [midway, below]{$P(k=i+2|\lambda=1)$}(t3);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i+1|\lambda=1)$}(t2);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i-1|\lambda=1)$} (t);
\draw [->,dashed] (t1) to [out=-155,in=-20] node [midway, below]{$P(k=i-2|\lambda=1)$}(tt);
\draw [->,dashed] (t1) to [out=135,in=15] node [midway, above] {$P(k=0|\lambda=1)$}(t0);
\end{tikzpicture}
编辑1 时间序列示例
\begin{tikzpicture}
\begin{axis}[name=p, legend pos=south west, grid =major, symbolic x coords= {$t_1$,$t_2$,$t_3$,$t_4$,$t_5$,$t_6$,$t_7$,$t_8$,$t_9$,$t_n$}]
\addplot+[smooth, color=blue] coordinates {
($t_1$,42)
($t_2$,43)
($t_3$,42)
($t_5$,41)
($t_7$,34.1)
($t_8$,40)
($t_9$,40.5)
($t_n$,41)};
\end{axis}
\end{tikzpicture}
答案1
编辑:我还暂时显示了您所请求的内容。
\documentclass[border=2mm,tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{positioning,calc}
\pgfplotsset{width=16cm,height=6cm,compat=1.15}
\begin{document}
\begin{tikzpicture}[main/.style={circle, minimum size = 10mm, thick, draw =black!80, node distance = 10mm},
box/.style={rectangle, draw=black!100}]
\begin{axis}[name=p, legend pos=south west, grid =major,
symbolic x coords={$t_0$,$t_1$,$t_2$,$t_3$,$t_4$,$t_5$,$t_6$,$t_7$,$t_8$,$t_9$,$t_{10}$,$t_n$}]
\addplot+[smooth, color=blue] coordinates {
($t_0$,42)
($t_1$,43)
($t_2$,42)
($t_5$,41)
($t_8$,34.1)
($t_9$,40)
% ($t_{11}$,40.5)
($t_n$,41)};
\coordinate (T1) at (axis cs:{[normalized]-1},0);
\coordinate (T2) at (axis cs:{[normalized]1},0);
\coordinate (T3) at (axis cs:{[normalized]2},0);
\coordinate (T5) at (axis cs:{[normalized]5},0);
\coordinate (T8) at (axis cs:{[normalized]8},0);
\coordinate (T9) at (axis cs:{[normalized]9},0);
\coordinate (T10) at (axis cs:{[normalized]10},0);
\coordinate (T11) at (axis cs:{[normalized]11},0);
\end{axis}
\node[main,draw =red!80] (t1) at (T5|- 0,-3){$t_i$};
\node[main] (t2) at (T8|- 0,-3) {$t_{i+1}$};
\node[main] (t3) at (T9|- 0,-3) {$t_{i+2}$};
\node[main] (tn) at (T11|- 0,-3) {$t_{n}$};
\node[main] (t) at (T3|- 0,-3) {$t_{i-1}$};
\node[main] (tt) at (T2|- 0,-3) {$t_{i-2}$};
\node[main] (t0) at (T1|- 0,-3) {$t_{0}$};
% make path ...
\path (t3) -- node[auto=false]{\ldots} (tn);
\path (tt) -- node[auto=false]{\ldots} (t0);
% draw arrows
\draw [->,dashed] (t1) to [out=45,in=165] node [midway, above] {$P(k=n|\lambda=1)$} (tn);
\draw [->,dashed] (t1) to [out=-10,in=-155] node [midway, below]{$P(k=i+2|\lambda=1)$}(t3);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i+1|\lambda=1)$}(t2);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i-1|\lambda=1)$} (t);
\draw [->,dashed] (t1) to [out=-155,in=-20] node [midway, below]{$P(k=i-2|\lambda=1)$}(tt);
\draw [->,dashed] (t1) to [out=135,in=15] node [midway, above] {$P(k=0|\lambda=1)$}(t0);
\end{tikzpicture}
\end{document}
我认为它不是太漂亮。
更新:尝试显示您的数据。请注意,有时需要将绘图宽度与使用固定距离的图形依赖性绘图同步。
\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}[main/.style={circle, minimum size = 10mm, thick, draw =black!80, node distance = 10mm},
box/.style={rectangle, draw=black!100}]
% put nodes
\node[main,draw =red!80] (t1) {$t_i$};
\node[main] (t2) [right= 3cm of t1] {$t_{i+1}$};
\node[main] (t3) [right= of t2] {$t_{i+2}$};
\node[main] (tn) [right= of t3] {$t_{n}$};
\node[main] (t) [left= 3cm of t1] {$t_{i-1}$};
\node[main] (tt) [left= of t] {$t_{i-2}$};
\node[main] (t0) [left= of tt] {$t_{0}$};
% make path ...
\path (t3) -- node[auto=false]{\ldots} (tn);
\path (tt) -- node[auto=false]{\ldots} (t0);
% draw arrows
\draw [->,dashed] (t1) to [out=45,in=165] node [midway, above] {$P(k=n|\lambda=1)$} (tn);
\draw [->,dashed] (t1) to [out=-10,in=-155] node [midway, below]{$P(k=i+2|\lambda=1)$}(t3);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i+1|\lambda=1)$}(t2);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i-1|\lambda=1)$} (t);
\draw [->,dashed] (t1) to [out=-155,in=-20] node [midway, below]{$P(k=i-2|\lambda=1)$}(tt);
\draw [->,dashed] (t1) to [out=135,in=15] node [midway, above] {$P(k=0|\lambda=1)$}(t0);
\coordinate[above=2cm of t0] (O);
\coordinate (F) at (O -|tn);
\begin{scope}[shift=(O),yscale=3]
\draw [thick,-latex] (O) -- ($(F)+(1,0)$) node[right]{$t$};
\draw [thick,-latex] (O) -- ++(0,1.5);
\draw[smooth,blue,thick] plot coordinates {(0,1.1) (2,1.2)
(4,1.3)
(6,1.2)
(8,1.1)
(10,0.41)
(12,1.0)
(14,1.05)
(16,1.1)};
\foreach \X/\Y in {t1/{$t_i$},t2/{$t_{i+1}$},t3/{$t_{i+2}$},tn/{$t_{n}$},t/{$t_{i-1}$},tt/{$t_{i-2}$},t0/{$t_{0}$}}
{\draw (O-|\X) -- ++(0,-1mm) node[below] {\Y};}
\end{scope}
\end{tikzpicture}
\end{document}
并进一步完善 Torbjørn T. 的建议
\draw[smooth,blue,thick] plot coordinates {(t0|-0,1.1) (tt|-0,1.2)
(t|-0,1.3)
(t1|-0,1.2)
(t2|-0,0.41)
(t3|-0,1.1)
(tn|-0,1.0)};
产量
问题是您是否想为此使用 pgfplots。您可以,但您需要使用不同的方法来实现相互“同步”。
原始答案:
\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{positioning,calc}
\newcommand{\randomlist}[4]{% points, displacement,seed, y0
\xdef\y{#4}
\pgfmathsetseed{#3}
\foreach \x [count=\n] in {0,...,#1}
{
\pgfmathparse{\y + rand*#2} % computing next step of random walk
\xdef\y{\pgfmathresult}
\xdef\finaly{\pgfmathresult}
\xdef\finaln{\n}
\ifnum\n=1\relax
\xdef\lst{(\x,\y)}
\else
\global\xdef\lst{\lst\space (\x,\y)}
\fi
}
}
\begin{document}
\begin{tikzpicture}[main/.style={circle, minimum size = 10mm, thick, draw =black!80, node distance = 10mm},
box/.style={rectangle, draw=black!100}]
% put nodes
\node[main,draw =red!80] (t1) {$t_i$};
\node[main] (t2) [right= 3cm of t1] {$t_{i+1}$};
\node[main] (t3) [right= of t2] {$t_{i+2}$};
\node[main] (tn) [right= of t3] {$t_{n}$};
\node[main] (t) [left= 3cm of t1] {$t_{i-1}$};
\node[main] (tt) [left= of t] {$t_{i-2}$};
\node[main] (t0) [left= of tt] {$t_{0}$};
% make path ...
\path (t3) -- node[auto=false]{\ldots} (tn);
\path (tt) -- node[auto=false]{\ldots} (t0);
% draw arrows
\draw [->,dashed] (t1) to [out=45,in=165] node [midway, above] {$P(k=n|\lambda=1)$} (tn);
\draw [->,dashed] (t1) to [out=-10,in=-155] node [midway, below]{$P(k=i+2|\lambda=1)$}(t3);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i+1|\lambda=1)$}(t2);
\draw [->,dashed] (t1) to node [midway, above] {$P(k=i-1|\lambda=1)$} (t);
\draw [->,dashed] (t1) to [out=-155,in=-20] node [midway, below]{$P(k=i-2|\lambda=1)$}(tt);
\draw [->,dashed] (t1) to [out=135,in=15] node [midway, above] {$P(k=0|\lambda=1)$}(t0);
\coordinate[above=2cm of t0] (O);
\coordinate (F) at (O -|tn);
\begin{scope}[shift=(O)]
\draw [thick,-latex] (O) -- ($(F)+(1,0)$) node[right]{$t$};
\draw [thick,-latex] (O) -- ++(0,4);
\randomlist{16}{0.4}{7}{1.4}% play with these parameters to get another curve
\draw[smooth,blue,thick] plot coordinates {\lst};
\foreach \X/\Y in {t1/{$t_i$},t2/{$t_{i+1}$},t3/{$t_{i+2}$},tn/{$t_{n}$},t/{$t_{i-1}$},tt/{$t_{i-2}$},t0/{$t_{0}$}}
{\draw (O-|\X) -- ++(0,-1mm) node[below] {\Y};}
\end{scope}
\end{tikzpicture}
\end{document}