
我不熟悉 Tikz 包,以下程式碼是根據我同事的現有程式碼修改的。這是馬可夫鏈圖。我盡力了,但是彎曲箭頭從州的中心開始,我希望它們從州的邊緣開始。還有其他方法嗎?感謝您的幫忙!
\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}
答案1
這是因為你畫的圓圈不是節點,所以 TikZ 不知道它必須在其邊界上啟動箭頭。你最好給你的節點一個最小尺寸和形狀(圓形,這裡)並告訴TikZ 來繪製它們。
\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}
現在,說實話,這不是繪製此類圖表的最佳方法。你應該學習 hox 來使用chains
和 繪圖edges
,也許使用quotes
圖書館。因為你不熟悉 Ti,所以我沒有修改太多你的程式碼kZ,但您會在這個網站上找到許多馬可夫鏈的好例子。
答案2
這是給你的建議。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\def\a{2.5}
\path[nodes={circle,draw,minimum size=12mm}]
(0,0) node (1) {$1$}
++(\a,0) node (2) {$2$}
++(\a,0) node (3) {$3$}
;
\draw[<-] (1)--+(90:2) node[midway,right]{$\pi_1$};
\draw[->] (1)--(2) node[midway,above]{$x^{(m)}$};
\draw[->] (2)--(3) node[midway,above]{$D^{(m)}$};
\draw[->] (1) to[out=60,in=120] (3);
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}