Graphviz

From Network Security Wiki
Jump to navigation Jump to search


Installation

Installation in Ubuntu:

sudo apt install graphviz

Sample Script

import graphviz
dot = graphviz.Digraph(comment='My Network File')
dot.attr('node', shape='box')
dot.node('A', "Router")
dot.node('B', "Router2")
dot.node('C', "Router3")
dot.edges(['AB', "AC"])
dot.edge('B','C',constraint='false')
dot.render('Router', view=False, format="png")

DOT File

Using DOT File format:

from graphviz import Source
temp = """
digraph G{
edge [dir=forward]
node [shape=plaintext]

0 [label="0 (None)"]
0 -> 5 [label="root"]
1 [label="1 (Hello)"]
2 [label="2 (how)"]
2 -> 1 [label="advmod"]
3 [label="3 (are)"]
4 [label="4 (you)"]
5 [label="5 (doing)"]
5 -> 3 [label="aux"]
5 -> 2 [label="advmod"]
5 -> 4 [label="nsubj"]
}
"""
dot = Source(temp, filename="test.gv", format="png")
dot.view()


Using DOT file:

nano dot_file
edge [dir=forward]
node [shape=plaintext]

0 [label="0 (None)"]
0 -> 5 [label="root"]
1 [label="1 (Hello)"]
2 [label="2 (how)"]
2 -> 1 [label="advmod"]
3 [label="3 (are)"]
4 [label="4 (you)"]
5 [label="5 (doing)"]
5 -> 3 [label="aux"]
5 -> 2 [label="advmod"]
5 -> 4 [label="nsubj"]
   Ambox notice.png     This section needs Testing!
from graphviz import Source
path = '/home/test/dot_file'
dot = Source.from_file(path)
dot.view()


References




blog comments powered by Disqus