2

I almost finished a diagram on pgfplot, but a few details are still missing. I hope some of you are willing to help me.

This is the almost completed diagram:

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\pgfplotsset{compat=1.13}
\begin{document}
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=middle, 
title style={yshift=6ex},
grid=both,
xlabel=$Time~(T_n)$, ylabel=$States~(X_n)$,
xmin=0,xmax=20,
ymin=0,ymax=4,
axis line style={-Latex[round]},
ticklabel style={font=\footnotesize,fill=white},
extra x ticks={0},
extra x tick labels ={$t_0$},
xtick={1.2, 2.4, 3.6, 4.8, 6, 7.2, 8.4, 9.6, 10.8, 12, 13.2, 14.4, 15.6, 16.8, 18, 19.2},
xticklabels={$t_1$, $t_2$, $t_3$, $t_4$, $t_5$, $t_6$, $t_7$, $t_8$, $t_9$, $t_{10}$, $t_{11}$, $t_{12}$, $t_{13}$, $t_{14}$, $t_{15}$, $t_{16}$},
ytick={0.5, 1, 1.5, 2, 2.5, 3, 3.5},
yticklabels={$CCC$, $B$, $BB$, $BBB$, $A$, $AA$, $AAA$},
extra y ticks={0},
extra y tick labels={$D$},
yticklabel style={anchor=east},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west},
width=11cm,
]
\end{axis}
\begin{axis}[
at={(0,-0.7cm)}, 
axis x line*=left, axis y line=none,
xticklabels={$T_0$, $T_1$, $T_2$, \scriptsize{$s$}, $T_3$, $T_4$, $T_5$, $T_6$, \scriptsize{$s$}\tiny{+}\scriptsize{$t$}, $T_7$},
xtick={0, 2.4, 4.8, 6, 8.4,  12, 13.2, 15.6, 16.8, 18},
axis line style={-Latex[round]},
ticklabel style={font=\footnotesize,fill=white},
xmin=0,xmax=20,
ymin=0,ymax=4,
ytick={0.5, 1, 1.5, 2, 2.5, 3, 3.5},
width=11cm,
]
\addplot[->,>={}] coordinates{
(0,2.855)
(2.4,2.855)

(2.4,1.855)
(4.8,1.855)

(4.8,1.355)
(8.4,1.355)

(8.4,0.855)
(12,0.855)

(12,2.355)
(13.2,2.355)

(13.2,2.355)
(15.6,2.355)

(15.6,3.355)
(18,3.355)

(18.1,1.355)
(20,1.355)

};
\draw [fill,black] (0.05,2.855) circle [radius=1.5pt];
\draw [fill,black] (2.4,1.855) circle [radius=1.5pt];
\draw [fill,black] (4.8,1.355) circle [radius=1.5pt];
\draw [fill,black] (8.4,0.855) circle [radius=1.5pt];
\draw [fill,black] (12,2.355) circle [radius=1.5pt];
\draw [fill,black] (13.2,2.355) circle [radius=1.5pt];
\draw [fill,black] (15.6,3.355) circle [radius=1.5pt];
\draw [fill,black] (18,1.355) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\end{document}

In this picture I added the few details I'm still missing:

enter image description here

It shouldn't be hard for someone used to pgfplots. Note that even something similar to the one suggested would be of great help. Thanks!

2
  • You are just asking for someone to complete your work. You need to describe, what problems you have with what part, and ideally create a Minimal example, with only that bit. Nov 22, 2016 at 10:51
  • My problems are: 1) The arrows pointing to the $X_0, ... , X_n$ variables. I really have no idea on how to draw it like that 2) I don't know how to draw colored lines (like the red and the blue one in the picture) 3) How to put text inside the diagram (e.g. the "X_0=A" text) 4) Is it possible to draw dotted vertical lines? Nov 22, 2016 at 12:42

1 Answer 1

2

As a starting point, a part of solution is as follows.

1- Add overbrace style to your tikzpicture environment:

\begin{tikzpicture}[
brc/.style args = {#1/#2}{decorate,
              decoration={brace, amplitude=5pt,
              raise=#1,#2},% for mirroring of brace
              thick}]  

\begin{axis}[
axis lines=middle, 
title style={yshift=6ex},
.
.
.

2- Drawing:

\draw [fill,black] (0.05,2.855)coordinate (X0) circle [radius=1.5pt] node[above right=0.2cm]{\tiny $X_0=A$};
\draw [-latex] (X0)--++(20:0.5);
\draw [fill,black] (2.4,1.855)coordinate (X1) circle [radius=1.5pt] node[above right=0.2cm]{\tiny $X_1=BB$};
\draw [-latex] (X1)--++(20:0.5);
\draw [fill,black] (4.8,1.355) circle [radius=1.5pt];
\draw [fill,black] (8.4,0.855) circle [radius=1.5pt];
\draw [fill,black] (12,2.355) circle [radius=1.5pt];
\draw [fill,black] (13.2,2.355) circle [radius=1.5pt];
\draw [fill,black] (15.6,3.355) circle [radius=1.5pt];
\draw [fill,black] (18,1.355) circle [radius=1.5pt];
\draw [dashed] (6,0)--(6,1.5);
\draw [red] (4.8,0.5)--(6,0.5);
\draw [brc=1mm/] (4.8,0.5)--node[above=3mm]{\tiny $=l$}(6,0.5);
%\draw[decorate,decoration={overbrace,amplitude=3pt,mirror}] (4.8,0.5) -- (6,0.5 );
\draw [blue] (6,0.5)--(8.4,0.5);
\draw [brc=1mm/] (6,0.5)--node[above=3mm]{\tiny $=u$}(8.4,0.5);

will produce:

enter image description here

1
  • 1
    if you add clip mode=individual to the axis options, you avoid the dot at A being half-cut.
    – Rmano
    Nov 22, 2016 at 13:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .