Data Visualization - Dot Lang & Graphviz

Data Visualization - Dot Lang & Graphviz

Graphviz安裝

依據官網http://www.graphviz.org/Download..php講述的下載、安裝方式進行。

Windows:
下載:http://www.graphviz.org/pub/graphviz/stable/windows/graphviz-2.38.msi
以管理員權限運行 graphviz-x.xx.msi

Warning for Vista users: Even if you are logged in as adminstrator, double-clicking on the MSI file or running the MSI file from a command prompt may still not may not provide sufficient privileges. You have to run “msiexec /a graphviz-x.xx.msi”.1

配置環境變量,將X:\PATH_TO_Graphviz2.38\bin加入到PATH中

Note: As of version 2.31, the Visual Studio package no longer alters the PATH variable or accesses the registry at all. If you wish to use the command-line interface to Graphviz or are using some other program that calls a Graphviz program, you will need to set the PATH variable yourself.2

Redhat/Centos:
使用yum Repository
設置yum源 graphviz-rhel.repo 到 /etc/yum.repos.d/
執行安裝

yum list available 'graphviz*'
yum install 'graphviz*'

或者下載各個組件的rpm安裝包進行安裝,參考http://www.graphviz.org/Download_linux_rhel.php

Ubuntu:
目前有一個graphviz開發版可用於apt-get 安裝,參考https://launchpad.net/~gviz-adm/+archive/ubuntu/graphviz-dev
或者下載各個組件的deb安裝包進行安裝,參考http://www.graphviz.org/Download_linux_ubuntu.php

Anaconda (如果你使用Python則推薦這種方式):
不管是Linux, windows, osx操作系統,安裝好anaconda之後運行

conda install -c anaconda graphviz=2.38.0

即可完成安裝。

graphviz conda package 並不是 Python package,如果使用import graphviz則會報出” no module named graphviz “錯誤,這便是因爲graphviz conda package 僅是將lib files放入了library/中,例如dot可以在”/PATH_TO_ANACONDA/bin/”目錄中找到並執行。
如果要安裝graphviz Python package, 使用”pip install graphviz”3

最近使用yum安裝時出現錯誤
這裏寫圖片描述
目前這個BUG已經被提交,還沒有進一步更新。45

安裝完成後執行

dot -version

顯示graphviz相關的版本信息
這裏寫圖片描述

還可以打開graphviz的編輯器gvedit

gvedit

這裏寫圖片描述


DOT語言

DOT (graph description language)
DOT是一種用文本文件表示的圖像描述語言,一般DOT文件以”gv”或者”dot”爲後綴(”gv”的表示方式是用來跟早期(2007之前)的Microsoft Word區分)。6

Syntax

DOT 的抽象語法表達7

     graph  :   [ strict ] (graph | digraph) [ ID ] '{' stmt_list '}'
 stmt_list  :   [ stmt [ ';' ] stmt_list ]
      stmt  :   node_stmt
            |   edge_stmt
            |   attr_stmt
            |   ID '=' ID
            |   subgraph
 attr_stmt  :   (graph | node | edge) attr_list
 attr_list  :   '[' [ a_list ] ']' [ attr_list ]
    a_list  :   ID '=' ID [ (';' | ',') ] [ a_list ]
 edge_stmt  :   (node_id | subgraph) edgeRHS [ attr_list ]
   edgeRHS  :   edgeop (node_id | subgraph) [ edgeRHS ]
 node_stmt  :   node_id [ attr_list ]
   node_id  :   ID [ port ]
      port  :   ':' ID [ ':' compass_pt ]
            |   ':' compass_pt
  subgraph  :   [ subgraph [ ID ] ] '{' stmt_list '}'
compass_pt  :   (n | ne | e | se | s | sw | w | nw | c | _)

可以參考wiki中的幾個例子來解釋DOT語法。8
Undirected graphs (無向圖)
Directed graphs (有向圖)
Attributes (屬性)
屬性字典請參考:http://www.graphviz.org/content/attrs
Comments (註釋)
更多示例可以參考:
http://blog.csdn.net/zhangskd/article/details/8250470
http://www.graphviz.org/Gallery.php

Layout programs

The DOT language defines a graph, but does not provide facilities for rendering the graph. There are several programs that can be used to render, view, and manipulate graphs in the DOT language:

Graphviz - A collection of libraries and utilities to manipulate and render graphs
Canviz - a JavaScript library for rendering dot files.
Viz.js - A simple Graphviz JavaScript client
Grappa - A partial port of Graphviz to Java.
Beluging - A Python & Google Cloud based viewer of DOT and Beluga extensions.
Tulip can import dot files for analysis
OmniGraffle can import a subset of DOT, producing an editable document. (The result cannot be exported back to DOT, however.)
ZGRViewer, a GraphViz/DOT Viewer link
VizierFX, A Flex graph rendering library link
Gephi - an interactive visualization and exploration platform for all kinds of networks and complex systems, dynamic and hierarchical graphs

未完待續……

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章