具有多个节点的圆形图

具有多个节点的圆形图

我有一个简单的圆形图,其中有 N 个节点。但是 N 可以任意大,所以我在节点之间使用省略号。我使用以下代码: 在此处输入图片描述

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{latexsym}
\usepackage[greek,english]{babel}
\usepackage{graphicx}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows, automata, positioning, calc}

\definecolor{lavander}{cmyk}{0,0.48,0,0}
\definecolor{violet}{cmyk}{0.79,0.88,0,0}
\definecolor{burntorange}{cmyk}{0,0.52,1,0}
\def\lav{lavander!90}
\def\oran{orange!30}

\begin{document}

\tikzset{%
   peer/.style={draw,circle,violet,bottom color=red, top color= white, text=violet, minimum width=25pt},
   superpeer/.style={draw, circle,  left color=burntorange, text=violet, minimum width=25pt},
   point/.style = {fill=black,inner sep=1pt, circle, minimum width=5pt,align=right,rotate=60},
   forward edge/.style={->, >=stealth, shorten >=0pt, thick, color=blue},
   }

\def \n {8}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick]
\node[superpeer] (A) at ({360/\n * (1 - 1)}:3.5){$0$};
\node[peer]         (B)  at ({360/\n * (2 - 1)}:3.5){$1$};
\node[peer]         (C)  at ({360/\n * (3 - 1)}:3.5){$2$};
\node[peer]         (D)   at ({360/\n * (4 - 1)}:2.5){$3$};
\node[point] (p1)  at ({360/\n * (4.5 - 1)}:2.5){};
\node[point] (p2)  at ({360/\n * (4.6- 1)}:2.5){};  
\node[point] (p3)  at ({360/\n * (4.7 - 1)}:2.5){};
\node[peer] (E) at ({360/\n * (7 - 1)}:3.5) {$N$};
\path (A) edge [color=blue, bend right=20, above, sloped] node[]{$\lambda_{01}, \mu_{01}$} (B);
\path (B) edge [color=blue, bend right=20, above, sloped] node[]   {$\lambda_{12}, \mu_{12}$} (C);
\path (C) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{23}, \mu_{23}$}(D);
\path (A) edge [color=blue, bend left=20, above, sloped] node[]{$\lambda_{0N}, \mu_{0N}$} (E);
\path (B) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{10}, \mu_{10}$}(A);
\path (C) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{21}, \mu_{21}$}(B);
\path (D) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{32}, \mu_{32}$}(C);
\path (E) edge [color=blue, bend right=20, below, sloped] node[] {$\lambda_{{N-1},N}, \mu_{{N-1},N}$}(A);
\end{tikzpicture}

\end{document}

但结果并不理想。圆圈几乎不对称,省略号本身就是一个痛点。有人能帮我把这个图“专业化”吗?谢谢!

答案1

基于您的代码的解决方案。这可以作为进一步简化代码的起点。不对称来自于\n=8代码中定义的点数不足(仅 5 个)。更正方法是添加额外的点 A1、B1 和 C1 并正确分配它们的位置。此解决方案还建议foreach loop简化代码。

在此处输入图片描述

代码

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{latexsym}
\usepackage[greek,english]{babel}
\usepackage{graphicx}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows, automata, positioning, calc}

\definecolor{lavander}{cmyk}{0,0.48,0,0}
\definecolor{violet}{cmyk}{0.79,0.88,0,0}
\definecolor{burntorange}{cmyk}{0,0.52,1,0}
\def\lav{lavander!90}
\def\oran{orange!30}

\begin{document}

\tikzset{%
   peer/.style={draw,circle,violet,bottom color=red, top color= white, text=violet, minimum width=25pt},
   superpeer/.style={draw, circle,  left color=burntorange, text=violet, minimum width=25pt},
   point/.style = {fill=black,inner sep=1pt, circle, minimum width=5pt,align=right,rotate=60},
%   forward edge/.style={->, >=stealth, shorten >=0pt, thick, color=blue},
   }

\def \n {8}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick]
\node[superpeer]    (A)   at ({360/\n * (1 - 1)}:2.5){$3$};
\node[peer]         (B)   at ({360/\n * (2 - 1)}:2.5){$2$};
\node[peer]         (C)   at ({360/\n * (3 - 1)}:2.5){$1$};
\node[peer]         (D)   at ({360/\n * (4 - 1)}:2.5){$N$};
\node[peer]         (E)   at ({360/\n * (5 - 1)}:2.5){$7$};
\node[peer]         (A1)  at ({360/\n * (6 - 1)}:2.5){$6$};
\node[peer]         (B1)  at ({360/\n * (7 - 1)}:2.5){$5$};
\node[peer]         (C1)  at ({360/\n * (8 - 1)}:2.5){$4$};
\node[point] (p1)  at ({360/\n * (4.4 - 1)}:2.5){};
\node[point] (p2)  at ({360/\n * (4.5 - 1)}:2.5){};  
\node[point] (p3)  at ({360/\n * (4.6 - 1)}:2.5){};


\path (A) edge [color=blue, bend right=20, above, sloped] node[]{$\lambda_{23}, \mu_{23}$} (B);
\path (B) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{32}, \mu_{32}$}(A);

\path (B) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{21}, \mu_{21}$} (C);
\path (C) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{12}, \mu_{12}$}(B);

\path (C) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{N1}, \mu_{N1}$}(D);
\path (D) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{N1}, \mu_{N1}$}(C);

\path (A1) edge [color=blue, bend right=20, above, sloped] node[]{$\lambda_{67}, \mu_{67}$} (E);
\path (E) edge [color=blue, bend right=20, below, sloped] node[] {$\lambda_{76}, \mu_{76}$}(A1);

\path (A) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{34}, \mu_{34}$} (C1);
\path (C1) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{43}, \mu_{43}$}(A);

\path (A1) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{65}, \mu_{65}$} (B1);
\path (B1) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{56}, \mu_{56}$}(A1);

\path (C1) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{45}, \mu_{45}$}(B1);
\path (B1) edge [color=blue, bend right=20, above, sloped] node[] {$\lambda_{54}, \mu_{54}$}(C1);
\end{tikzpicture}

\end{document}

编辑:简化代码通过foreach loop

在此处输入图片描述

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{latexsym}
\usepackage[greek,english]{babel}
\usepackage{graphicx}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows, automata, positioning, calc}

\definecolor{lavander}{cmyk}{0,0.48,0,0}
\definecolor{violet}{cmyk}{0.79,0.88,0,0}
\definecolor{burntorange}{cmyk}{0,0.52,1,0}
\def\lav{lavander!90}
\def\oran{orange!30}

\begin{document}

\tikzset{%
   peer/.style={draw,circle,violet,bottom color=red, top color= white, text=violet, minimum width=25pt},
   superpeer/.style={draw, circle,  left color=burntorange, text=violet, minimum width=25pt},
   point/.style = {fill=black,inner sep=1pt, circle, minimum width=5pt,align=right,rotate=60},
%   forward edge/.style={->, >=stealth, shorten >=0pt, thick, color=blue},
   }

\def \n {8}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick]

\node[peer]          (C)   at ({360/\n * (3 - 1)}:2.5){$1$};
\node[peer]          (B)   at ({360/\n * (2 - 1)}:2.5){$2$};
\node[superpeer]     (A)   at ({360/\n * (1 - 1)}:2.5){$3$};
\node[peer]         (C1)   at ({360/\n * (8 - 1)}:2.5){$4$};
\node[peer]         (B1)   at ({360/\n * (7 - 1)}:2.5){$5$};
\node[peer]         (A1)   at ({360/\n * (6 - 1)}:2.5){$6$};
\node[peer]         (E)    at ({360/\n * (5 - 1)}:2.5){$7$};
\node[peer]         (D)    at ({360/\n * (4 - 1)}:2.5){$N$};

\node[point] (p1)  at ({360/\n * (4.4 - 1)}:2.5){};
\node[point] (p2)  at ({360/\n * (4.5 - 1)}:2.5){};  
\node[point] (p3)  at ({360/\n * (4.6 - 1)}:2.5){};

\foreach \s/\e/\f/\t in {D/C/N/1,C/B/1/2,B/A/2/3,A/C1/3/4,C1/B1/4/5,B1/A1/5/6,A1/E/6/7}
{\path (\s) edge [color=blue, bend right=20, above, sloped] node[]{\tiny $\lambda_{\f\t},\mu_{\f\t}$} (\e);
 \path (\e) edge [color=blue, bend right=20, above, sloped] node[]{\tiny $\lambda_{\t\f},\mu_{\t\f}$} (\s);
};

\end{tikzpicture}

\end{document}

答案2

编辑:我误解你了。你实际上并不想绘制N节点,而是绘制一个通用图表。在这种情况下,我下面使用的极坐标符号(angle:radius)是你的好朋友,应该可以回答你所有的问题。

我这里有一个起点。(请注意示例的大小)。您现在只需添加样式选项和特定标签。

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\def \n {8}

\begin{tikzpicture}
\node (node0) at (0:3) {0};
\def\lasti{0} %fixing bug for older tikz versions
\foreach[
    evaluate=\i as \angle using (\i)*360/(\n+1),
    remember=\i as \lasti (initialy 0)
] \i in {1,...,\n} {
    \node (node\i) at (\angle:3) {\i};
    \draw (node\i) edge[<-,bend left=20] 
        node[pos=0.5,sloped,above] {$\lambda_{\i}$} 
    (node\lasti);
    \draw (node\i) edge[->,bend right=20] 
            node [pos=0.5,sloped,above] {$\lambda_{\i}$} 
    (node\lasti);
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容