0
0

graph_viz

Posted at
import graphviz as gv

# ノードのリスト
text1 = 'this is sample text \n hello'
nodes = [text1, 'B', 'C', 'D', 'E', 'F']

# Digraphオブジェクトを作成
graph = gv.Digraph(format='svg', filename="output/mygraph.gv",
                   graph_attr=dict(rankdir='LR', splines='ortho'),
                   node_attr=dict(shape='box'))

# ノードを5つずつ追加
graph.node(nodes[0])
graph.node(nodes[1])
graph.node(nodes[2])
graph.node(nodes[3])
graph.node(nodes[4])
graph.node(nodes[5])

# エッジを追加
graph.edge(text1, 'B')
graph.edge('B', 'C')
graph.edge('C', 'D')
graph.edge('D', 'E', constraint='false')
graph.edge('E', 'F')

graph.view()

from graphviz import Digraph

# Digraphオブジェクトを作成します
dot = Digraph()

# ノードを追加します
dot.node('A', 'Start', shape='box')
dot.node('B', 'Process 1', shape='box')
dot.node('C', 'Process 2', shape='box')
dot.node('D', 'End', shape='box')

# エッジを追加します
dot.edges(['AB', 'BC', 'CD'])

# 一段目の最後から二段目の最初に矢印を追加します
dot.edge('B', 'C', constraint='false')

# レイアウトを横向きに設定します
dot.attr(rankdir='LR')

# ファイルに保存して表示します
dot.render('flowchart', format='png', cleanup=True)


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0