brew install graphviz
pip install graphviz
code
from graphviz import Digraph
#Output as png
dg = Digraph(format='png')
dg.node('1') #Set the node labeled 1
dg.node('2') #Set the node labeled 2.
dg.render('./test/dgraph1') #Save to test folder as dgraph(Do not write the extension)
__ Output result __
code
from graphviz import Digraph
dg = Digraph(format='png')
dg.node('1') #Set the node labeled 1
dg.node('2') #Set the node labeled 2.
dg.edge('1','2') #Draw an arrow from node 1 to node 2
dg.render('./test/dgraph2') #Save to test folder as dgraph
__ Output result __
See here for shape types
code
from graphviz import Digraph
dg = Digraph(format='png')
#Set the default to ○
dg.attr("node", shape="circle")
dg.node('1') #Set the node labeled 1(○)
dg.node('2') #Set the node labeled 1 (○)
dg.node('3',shape='box') #Change a specific node to □
dg.render('./test/dgraph') #Save to test folder as dgraph
__ Output result __
Mac: How to use graphviz with Python [From installation to operation check] Specify node font size in Python and Graphviz Node Shapes
Recommended Posts