我需要帮助绘制一个简单的马尔可夫链。这是我使用的代码:
\begin{tikzpicture}[
> = stealth',
auto,
prob/.style = {inner sep=1pt,font=\footnotesize}
]
\node[state] (a) {$1$};
\node[state] (b) [right of =a] {$2$};
\node[state] (c) [below right of=a,xshift=-0.5cm] {$3$};
\path[->] (a) edge[bend left=10] node[prob]{$1/2$} (b)
edge[bend left=10] node[prob]{$1/2$} (c)
(b) edge[bend left=10] node[prob]{$1/3$} (a)
edge[bend left=10] node[prob]{$2/3$} (c)
(c) edge[bend left=10] node[prob]{$1/3$} (a)
edge[bend left=10] node[prob]{$2/3$} (b);
\end{tikzpicture}
我的绘制结果是:
答案1
我建议使用这个简单的代码pstricks
:
\documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{pst-node}
\begin{document}
\[
\begin{psmatrix}[mnode=circle, rowsep=2cm, colsep=1.2cm]
1 & & 2\\
& 3
\end{psmatrix}
\psset{arrows=->, arrowinset=0.12, linejoin=1, labelsep=1pt, shortput=nab, arcangle=20}
\everypsbox{\scriptstyle}
\ncarc{1,1}{1,3}^{1/2} \ncarc{1,3}{1,1}^{1/2}
\psset{nrot=:U}
\ncarc{1,1}{2,2}^{1/3} \ncarc{2,2}{1,1}^{1/3}
\ncarc{1,3}{2,2}^{2/3} \ncarc{2,2}{1,3}^{2/3}
\]
\end{document}
答案2
另一个 Ti钾Z 解决方案:使用automata
、positioning
、quotes
+arrows.meta
库:
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{arrows.meta, automata,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 29mm and 17mm,
every edge/.style = {draw, -{Stealth[scale=1.2]}, bend left=15},
every edge quotes/.append style = {auto, inner sep=2pt, font=\footnotesize}
]
\node (n1) [state] {$1$};
\node (n3) [state,below right=of n1] {$3$};
\node (n2) [state,above right=of n3] {$2$};
%
\path (n1) edge ["$1/2$"] (n2)
edge ["$1/2$"] (n3)
(n2) edge ["$1/3$"] (n1)
edge ["$2/3$"] (n3)
(n3) edge ["$1/3$"] (n1)
edge ["$2/3$"] (n2);
\end{tikzpicture}
\end{document}
答案3
您也可以使用 命令tikz-cd
。
\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz, diagrams={>=stealth}}
\begin{document}
\[
\begin{tikzcd}[row sep=7em, column sep=4em, cells={nodes={draw, circle}}]
1 \arrow[rr, bend left=15, "1/2"] \arrow[rd, bend left=15, "1/2"] & &
2 \arrow[ll, bend left=15, "1/3"] \arrow[ld, bend left=15, "2/3"] \\
& 3 \arrow[lu, bend left=15, "1/3"] \arrow[ru, bend left=15, "2/3"]
\end{tikzcd}
\]
\end{document}
答案4
\documentclass{standalone}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}[>=latex]
\SetGraphUnit{3}
\Vertex {3} \NOWE(3){1} \NOEA(3){2}
\tikzstyle{EdgeStyle}=[->,bend left=15]
\tikzstyle{LabelStyle}=[fill=white]
\Edge[label=$1/2$](2)(1)
\Edge[label=$1/3$](1)(2)
\Edge[label=$1/3$](3)(1)
\Edge[label=$1/3$](1)(3)
\Edge[label=$1/3$](3)(2)
\Edge[label=$2/3$](2)(3)
\end{tikzpicture}
\end{document}