tikz-pgf – Drawing a Markov Chain Using Tikz

tikz-arrowstikz-pgf

I am not familiar with Tikz package, following code is modified from existing codes from my colleague. This is a Markov chain plot. I did my best, but the bending arrows start at the center of the states, I would like them to start at the edge of the states. Is there another way to do it? Thanks for your help!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}

%circle
\draw [thick] (-3.5,-1.6) circle [radius=0.6];
\draw [thick] (-0.9,-1.6) circle [radius=0.6];
\draw [thick] (1.7,-1.6) circle [radius=0.6];
\draw [thick] (6.8,-1.6) circle [radius=0.6];
\draw [thick] (9.4,-1.6) circle [radius=0.6];

%label state
\node (A) at (-3.5,-1.6) {1};
\node (B) at (-0.9,-1.6) {2};
\node (C) at (1.7,-1.6) {3};
\node (D) at (6.8,-1.6) {$m$};
\node (E) at (9.4,-1.6) {$m+1$};

%horizontal arrow
\draw [->, thick] (-2.9,-1.6) --(-1.5,-1.6);
\draw [->, thick] (-0.3,-1.6) --(1.1,-1.6);
\draw [->, thick] (2.3,-1.6) --(3.7,-1.6);
\draw [->, thick] (4.8,-1.6) --(6.2,-1.6);
\draw [->, thick] (7.4,-1.6) --(8.8,-1.6);


%dots
\draw [thick, dotted] (3.7,-1.6) -- (4.8,-1.6);



%parameters - horizontal arrow
\node [above] at (-2.2,-1.6) {{\footnotesize $x^{(m)}$}};
\node [above] at (0.4,-1.6) {{\footnotesize $D^{(m)}$}};
\node [above] at (3,-1.6) {{\footnotesize $D^{(m-1)}$}};
\node [above] at (5.5,-1.6) {{\footnotesize $D^{(3)}$}};
\node [above] at (8.1,-1.6) {{\footnotesize $D^{(2)}$}};

%vertical arrow
\draw [->, thick] (-3.5,1) --(-3.5,-1);

%bending arrow
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(C);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(D);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(E);

\node [right] at (-3.5,0) {{\footnotesize $\displaystyle \pi_1$}};
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

Best Answer

This is because you drew the circles which are not nodes, so TikZ doesn't know it has to start the arrows on their borders. You'd better give your nodes a minimum size and a shape (circle, here) and tell TikZ to draw them.

Markov chain

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}[mystate/.style={draw,circle,minimum size=1.2cm}]

%circle
%\draw [thick] (-3.5,-1.6) circle [radius=0.6];
%\draw [thick] (-0.9,-1.6) circle [radius=0.6];
%\draw [thick] (1.7,-1.6) circle [radius=0.6];
%\draw [thick] (6.8,-1.6) circle [radius=0.6];
%\draw [thick] (9.4,-1.6) circle [radius=0.6];

%label state
\node[mystate] (A) at (-3.5,-1.6) {1};
\node[mystate] (B) at (-0.9,-1.6) {2};
\node[mystate] (C) at (1.7,-1.6) {3};
\node[minimum size=1.2cm] (C')at (4.25,-1.6){};
\node[mystate] (D) at (6.8,-1.6) {$m$};
\node[mystate] (E) at (9.4,-1.6) {$m+1$};

%horizontal arrow
\draw [->, thick] (A) -- (B) node[midway, above] {\footnotesize $x^{(m)}$};
\draw [->, thick] (B) -- (C) node[midway, above] {\footnotesize $D^{(m)}$};
\draw [->, thick] (C) -- (C') node[midway, above] {\footnotesize $D^{(m-1)}$};
\draw [->, thick] (C') -- (D) node[midway, above] {\footnotesize $D^{(3)}$};
\draw [->, thick] (D) -- (E) node[midway, above] {\footnotesize $D^{(2)}$};


%dots
\draw [thick, dotted] (3.7,-1.6) -- (4.8,-1.6);



%vertical arrow
\draw [->, thick] (-3.5,1) --(-3.5,-1);

%bending arrow
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(C);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(D);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(E);

\node [right] at (-3.5,0) {{\footnotesize $\displaystyle \pi_1$}};
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

Now, to be honest, this is not the best way to draw this kind of graph. You should learn hox to use chains, and draw edges, maybe using the quotes library. I didn't modify too much your code since you're not familiar with TikZ, but you would find many great examples of Markov chains on this site.