图形可视化包

图形可视化包

哪些软件包可用于图形可视化?我尝试过 Graphviz,但很难指导图形应如何显示。

我怎样才能制作出如示例中所示的图形(摘自图论与复杂网络:简介)。

在此处输入图像理论与复杂网络:简介描述 在此处输入图片描述 在此处输入图片描述

答案1

你可以使用 TikZ。这是一个非常简单的例子,

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[every node/.style={circle,inner sep=2pt,fill=black}]
  \node (A) at (0,0) {};
  \node (B) at (1,1) {};
  \node (C) at (0,1) {};
  \node (D) at (1,0) {};

  \draw (A) -- (B)
        (A) -- (C)
        (A) -- (D)
        (B) -- (D);
\end{tikzpicture}
\end{document}

在此处输入图片描述

您可以使用pstricks

\documentclass{article}
\usepackage{pstricks,pst-node}
\begin{document}
\begin{pspicture}[showgrid=false](1,1)
\pnode(0,0){A}
\pnode(1,1){B}    
\pnode(0,1){C}    
\pnode(1,0){D}    

\rput(A){\psdot}
\rput(B){\psdot}
\rput(C){\psdot}
\rput(D){\psdot}

\psline(A)(B)
\psline(A)(C)
\psline(A)(D)
\psline(B)(D)
\end{pspicture}
\end{document}

在此处输入图片描述

虽然下面的例子可以做得更高效一些,但它确实表明你可以制作出非常好的连接图:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}
  \def\mycircleofnodes{C0}
  \foreach \x in {0,30,...,330}
    {
      \node[circle,fill=black,inner sep=2pt] (C\x) at (\x:3) {} ;
      \ifnum\x>0\relax\xdef\mycircleofnodes{\mycircleofnodes,C\x}\fi
    }
  \foreach \x in {0,30,...,330}
    {
      \foreach \y in \mycircleofnodes
        {
          \draw (\y) -- (C\x);
        }
    }
\end{tikzpicture}

\end{document}

在此处输入图片描述

如果您不想将每个节点相互连接,那么您可以按照以下方式操作:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}
  \def\mycircleofnodes{C0}
  \foreach \x in {0,1,...,11}
    {
      \node[circle,fill=black,inner sep=2pt] (C\x) at (\x*30:3) {} ;
      \ifnum\x>0\relax\xdef\mycircleofnodes{\mycircleofnodes,C\x}\fi
    }

  \foreach \x/\y in {0/1,0/2,0/3,0/4,0/5,0/6,0/7,%
                     2/4,%
                     5/6,5/7,5/10,%
                     8/9,8/11}
    {
      \draw (C\x) -- (C\y);
    }

\end{tikzpicture}

\end{document}

在此处输入图片描述

以下(仅仅)是有关如何设置类似于第二个示例的内容的开始:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}

\def\rowA{0}
\def\rowB{0,1,...,9}
\def\rowC{0,1,...,17}
\def\rowD{0,1,...,13}
\def\rowE{0,1,...,5}
\def\rowF{0}

\begin{document}

\begin{tikzpicture}[x=0.5cm,
                    y=1.75cm,
                    every node/.style={circle,
                                       inner sep=2pt,
                                       fill=black}
                   ]

  \foreach \x in \rowA { \node (A\x) at (\x-0.5,2)  {}; }
  \foreach \x in \rowB { \node (B\x) at (\x-5,1)    {}; }
  \foreach \x in \rowC { \node (C\x) at (\x-9,0)    {}; }
  \foreach \x in \rowD { \node (D\x) at (\x-7,-1)   {}; }
  \foreach \x in \rowE { \node (E\x) at (\x-3,-2)   {}; }
  \foreach \x in \rowF { \node (F\x) at (\x-0.5,-3) {}; }

  \foreach \x    in {4,8,9}                    { \draw (A0)  -- (B\x); }
  \foreach \x/\y in {0/2,1/7,1/8,1/17}         { \draw (B\x) -- (C\y); }

  \foreach \x/\y in {0/0,0/7,0/8,0/10,1/4,1/8} { \draw (E\x) -- (D\y); }
  \foreach \x/\y in {0/0,0/1,0/2,0/3,0/4,0/5}  { \draw (F\x) -- (E\y); }

\end{tikzpicture}

\end{document}

在此处输入图片描述

请注意!pstrickstikz都有各自的学习曲线。它们都有充足的文档。 的文档pstricks分布在多个pdf文件中,有时当您不知道在哪里查找文档时,会感到沮丧。 tikz有一个庞大而全面的手册(尽管有时知道哪些库是必需的可能会有点令人沮丧)。

答案2

在此处输入图片描述 在此处输入图片描述

Asymptote提供了很多方便的编程方法来处理数据结构。下面是绘制圆形可视化图形的一种方法:

% visg.tex :
\documentclass{article}
\usepackage[inline]{asymptote}
\begin{asydef}
struct circGraph{    
  real r;
  string[] links;
  int n;

  pair node(int i){
    return rotate(90+i*360/n)*(r,0);
  }

  real lineW;
  pen linePen;
  pen[] linePens;

  pen nodePenO=invisible+3*linewidth(linePen);
  pen nodePenA=white;
  pen nodePenB=orange;

  real labelOff;

  void drawLines(){
    int lineCount;
    for(int i=0;i<links.length;++i){
      lineCount=0;
      for(int j=0;j<n;++j){
        if(substr(links[i],j,1)=="1"){
          draw(node(i)--node(j),linePens[lineCount]);
          ++lineCount;
        };
      }
    }
  }

  void drawNodes(){
    for(int i=0;i<n;++i){
      pair p=node(i);
      dot(p,nodePenO,RadialShade(nodePenA,nodePenB));
      label(string(i),labelOff*p);
    }
  }

  void operator init(
    string[] links
    ,real r=1
    ,pen[] linePens={lightred,darkgreen,blue}
    ,real lineW=0.6bp
    ,pen nodePenA=white
    ,pen nodePenB=orange
    ,real labelOff=1.08
  ){
    this.links    = links;
    this.r        = r;
    this.linePens = copy(linePens);
    this.lineW    = lineW;
    this.nodePenA = nodePenA;
    this.nodePenB = nodePenB;
    this.nodePenO=invisible+3*lineW;
    this.labelOff=labelOff;

    this.n=length(links[0]);
    this.linePens.cyclic=true;
    drawLines();
    drawNodes();
  }
}
\end{asydef}
\usepackage{lmodern}
\begin{document}
\begin{figure}
\begin{asy}
size(300);
defaultpen(fontsize(10pt));

string[] links={
"00000000000000000001100000000011100000000000000000",
"00000000000000000010000010000001101000000000000000",
"00000000000010100100000101100000001000000000000000",
"00000000000001010000100000000000000000000000000000",
"00000000000010000010000001100000000000000000000000",
"00000000000010000000000100000010100000000000000000",
"00000000000001000100000010100000000000000000000000",
"00000000000000001001000000000100001000000000000000",
"00000000000000000000110001100100000110000000000000",
"00000000000001101000100011010000000000000000000000",
"00000000000000000000000000000000001000000000000000",
"00000000000000000000000000000001000000000000000000",
"00000000000000000000000000000000000000100010100000",
"00000000000000000000000000000000000000000001001000",
"00000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000000000010100010000",
"00000000000000000000000000000000000000100000000000",
"00000000000000000000000000000000000000010000100010",
"00000000000000000000000000000000000000000100000000",
"00000000000000000000000000000000000001000100000010",
"00000000000000000000000000000000000000000000000100",
"00000000000000000000000000000000000000000010000000",
"00000000000000000000000000000000000000010000000000",
"00000000000000000000000000000000000000000100010000",
"00000000000000000000000000000000000000000001000000",
"00000000000000000000000000000000000000100000001000",
"00000000000000000000000000000000000000011010000100",
"00000000000000000000000000000000000000000000000001",
"00000000000000000000000000000000000000100001000000",
"00000000000000000000000000000000000000010000000001",
"00000000000000000000000000000000000000100001000000",
"00000000000000000000000000000000000000100000001000",
"00000000000000000000000000000000000000000100000000",
"00000000000000000000000000000000000001010000000010",
"00000000000000000000000000000000000000001000011000",
"00000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000000001000000000010",
"00000000000000000000000000000000000000010000000000",
"00000000000000000000000000000000000000010000000000",
};

circGraph(links); 
shipout(bbox(Fill(paleyellow)));

\end{asy}
\end{figure}
%
\begin{figure}
\begin{asy}
size(200);
defaultpen(fontsize(10pt));

string[] links={
"00000000110000000001110000",
"00000001000001000000110100",
"01010010000010110000000100",
"00101000010000000000000000",
"01000001000000110000000000",
"01000000000010000001010000",
"00100010000001010000000000",
"00000100100000000010000100",
"00000000011000110010000011",
"00110100010001101000000000",
"00000000000000000000000100",
};

currentpen=olive;
circGraph(links,linePens=new pen[]{black,white}
  ,nodePenA=yellow
  ,nodePenB=brown  
  ,labelOff=1.2); 
shipout(bbox(Fill(paleblue)));

\end{asy}
\end{figure}

\end{document}
%
% Process:
% pdflatex visg.tex    
% asy asy visg-*.asy
% pdflatex visg.tex

答案3

只是为了和 PSTricks 一起玩。

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}

\psset{showpoints}

\def\Graph#1{%
\begin{pspicture}(-2,-2)(2,2)
    \curvepnodes[plotpoints=\numexpr#1+1]{0}{360}{2 t PtoC}{P}
    \multido{\ix=0+1,\itemp=1+1}{\Pnodecount}{%
        \multido{\iy=\itemp+1}{\numexpr\Pnodecount-1-\ix}{\psline(P\ix)(P\iy)}}
\end{pspicture}}

\begin{document}
    \multido{\i=3+1}{10}{\Graph{\i}}
\end{document}

在此处输入图片描述

评论:

Pnodecount是最后一个等于plotpoints负 1 的索引。由于在完整圆形域的情况下,第一个点和最后一个点位于同一条径向线上,因此必须排除最后一个点。请注意一次错误指定循环范围时。

plotpoints在 中定义pst-plot,宏\curvepnodes在 中定义pst-node。当我们使用\curvepnodeswith时plotpoints,我们必须加载两个包。如果你忘记加载pst-plot(我经常这样做), 将\curvepnodes[plotpoints=...]...无法编译。我不知道这是否应该被视为应用于具有交叉链接的包的糟糕设计模式。

答案4

我回答了另一个问题这里但大部分答案都与您的问题相关。您想tikztkz-graph、 和tkz-berge包结合使用。漂亮的结果在 PDF 中“命名图表库”;它们与您给出的示例相当。图表包由 Alain Matthes 提供阿尔特蒙杜斯遗址. 计算机代数系统Sage 支持 tikz 和 Altermundus 的软件包以及 LaTeX

相关内容