1

I would like to reproduce with tikz the figure at the bottom. I did the graph dependence plot and I would like to add a time series above like you can seen.

Thank youenter image description here

As you can see i need perfect alignement between circle (node) t_i in the graph and the time t_i in the axis.

Bellow the tikz code for the graph dependency :

   \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}

EDIT 1 Example of time series

        \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}

enter image description here

  • 1
    What kind of data is in that time series? Do you have for example a text file of data that you want to plot, or do you just need some qualitative graph? – Torbjørn T. Feb 23 '18 at 21:49
  • no matter, I just want a quantitative time series with arbitrary values. Please look at my EDIT 1. – FiesAtoS Feb 23 '18 at 22:33
2

EDIT: I also show temporarily what you are requesting.

\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}

enter image description here

IMHO it is just not too beautiful.

UPDATE: An attempt to show your data. Note that at some point one needs to synchronize the width of the plot with your graph dependence plot, which uses fixed distances.

\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} 

enter image description here

And just fleshing out Torbjørn T.'s suggestion

 \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)}; 

yields

enter image description here

The question is if you want to you use pgfplots for this. You can, but then you need to use different methods for the mutual "synchronization".

Original answer:

\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}   

enter image description here

  • thanks, in fact i need simply an arbitrary time series like i showed in my Edit 1. can your solution be used in my case? Thanks agian – FiesAtoS Feb 23 '18 at 22:35
  • 1
    You could even use coordinates like (t0|-0,1.1) in the plot coordinates, to avoid the fixed x-values. – Torbjørn T. Feb 23 '18 at 22:55
  • it works very well thank you. however, I would like to know how to use my plot (axis with the grid) and not the coordinates as you did. Is there a way to synchronize my graph dependence plot and my axis plot (with grid) that I put in the edit?. – FiesAtoS Feb 24 '18 at 10:15
  • @FiesAtoS I added something along the lines you were suggesting. – marmot Feb 24 '18 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.