# How to draw a Cartesian plane like this one?

I read some topics on the forum, but still have no idea on how to draw a diagram like this one

I know I could just insert the image, but I think it would be nicer to draw it myself, and I also have to change the variables (I need to change S with T, X with J and J with X)

This is what I managed to achieve so far

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=middle, axis equal, title=test, xlabel={Time}, ylabel=.{States}]
x y
1.7 4.3
0 4.3

1.7 4
2.3 4

2.3 5.2
3.1 5.2

3.1 4.5
3.8 4.5

3.8 3.8
4.7 3.8

4.7 5.5
5.8 5.5
};
\end{axis}
\end{tikzpicture}
\end{document}


I still need the ticks on the "x" axis to be related to the jump points of the function, and to name them "T_0, T_1, ... T_n" (note that the jump length is random, and it has to be). Moreover, does anyone know how to remove the right dot from the function, leaving only the left one?

P.S: Of course I will add reference on the bibliography for using this image

A big hug to everybody!

• Have you tried modifying the code in my question (not yet answered). tex.stackexchange.com/q/339172/36667 Your question appears to be a special case of my question :) Nov 15 '16 at 9:15
• Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Nov 15 '16 at 9:27
• Hi! thanks for your reply. By copying and pasting your code as it is, I get an error at line 34: Missing \endcsname inserted <to be read again> \blankcount l.34 \blank ? Nov 15 '16 at 10:24
• Hi Stefan, I'll try and see what I can do. Thanks! Nov 15 '16 at 10:56
• I posted a code, but it still needs some modifications. Nov 15 '16 at 12:17

This is probably not the most flexible solution, but it's fairly straight forward I think. (You may well get better solutions from others later.) It also doesn't use pgfplots, just plain TikZ.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
axis/.style={thick,Latex-Latex},
xbar/.style={-Circle}
]

\draw [axis] (0,4) node[above] {States} |- (7,0) node[below] {time};

\foreach \y/\txt in {1/J_n=k,2/J_0=i,2.5/J_1=j}
\node [left=3mm] at (0,\y) {$\{\txt\}$};

\foreach [count=\i] \x/\txt in {0/0,1/1,1.8/2,3.2/n,5/n+1}
{
\node [below=3mm] (S\i) at (\x,0) {$S_{\txt}$};
\draw (\x,0) -- ++(0,{ifthenelse(\x>0,-3pt,0)});
}

\foreach \xA/\xB/\y in {0/1/2,1/1.8/2.5,3.2/5/1}
\draw [xbar] (\xA,\y) -- (\xB,\y);

\path (S3) -- node (dots1) {$\dots$} (S4);
\node [right=2mm] (dots2) at (S5.east) {$\dots$};
\node at (0,1.5 -| dots1) {$\dots$};
\node at (0,1 -| dots2) {$\dots$};

\node [below left] at (7,4) {
\begin{tabular}{c @{ : }l}
$(X_n)$ & sojourn time \\
$(J_n)$ & states of the system \\
$(S_n)$ & jump time
\end{tabular}};

\end{tikzpicture}
\end{document}

• I don't have words to say how much grateful I am. Lots and lots of thanks to you! Nov 15 '16 at 15:59