1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
% arara: indent: {overwrite: true, silent: on}
\documentclass[png,border=10pt,tikz]{standalone}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfkeys{/tikz/.cd,
vertical factor/.initial=0.5,
vertical factor/.get=\vertfactor,
vertical factor/.store in=\vertfactor,
start coordinate/.initial={0,\vertfactor},
start coordinate/.get=\startcoord,
start coordinate/.store in=\startcoord,
sample color/.initial=black,
sample color/.get=\samplecol,
sample color/.store in=\samplecol,
sample size/.initial=1pt,
sample size/.get=\samplesize,
sample size/.store in=\samplesize,
sample line width/.initial=very thick,
sample line width/.get=\samplelinewidth,
sample line width/.store in=\samplelinewidth,
}
\newcommand{\samplepath}[1]{%
\coordinate (start) at (\startcoord) ;
\foreach \samples[count=\xi from 1] in {#1}{%
\StrCut{\samples}{|}{\vertdir}{\hordir}
\ifnum\xi=1
\draw[\samplelinewidth,\samplecol](start)
--++(\hordir,0) coordinate (start);
\else
\IfStrEq{\vertdir}{+}{%true
\draw[\samplelinewidth,\samplecol]($(start)+(0,\vertfactor)$)
--++(\hordir,0)coordinate(start);
}{%false
\relax
}
\IfStrEq{\vertdir}{-}{%true
\draw[\samplelinewidth,\samplecol]($(start)+(0,-\vertfactor)$)
--++(\hordir,0)coordinate(start);
}{%false
\relax
}
\fi
}
}
\tikzset{sample/.style={
circle,
inner sep=\samplesize,
fill=\samplecol,
}
}
\newcommand{\discretesamplepath}[1]{%
\coordinate (start) at (\startcoord) ;
\foreach \samples[count=\xi from 1] in {#1}{%
\StrCut{\samples}{|}{\vertdir}{\hordir}
\ifnum\xi=1
\path(start)node[sample]{}
--++(\hordir,0) coordinate (start);
\else
\IfStrEq{\vertdir}{+}{%true
\path($(start)+(0,\vertfactor)$)node[sample]{}
--++(\hordir,0)coordinate(start);
}{%false
\relax
}
\IfStrEq{\vertdir}{-}{%true
\path($(start)+(0,-\vertfactor)$)node[sample]{}
--++(\hordir,0)coordinate(start);
}{%false
\relax
}
\fi
}
}
\begin{document}
\begin{tikzpicture}
% axis
\draw[-stealth] (0,-1)--(0,4) node[left]{$X(t)$};
\draw[-stealth] (-1,0)--(5,0) node[below]{$t$};
\samplepath{+|0.5,+|0.25,-|1.5,+|1,+|0.5,+|0.75}
\end{tikzpicture}
\end{document}
|