from graphviz import Digraph
from nbdevAuto.functions import graph
Graphviz
c1
c2
Diagram building tool
Customizing Nodes and Edges
= graph()
dot
'A', 'Start', shape='ellipse', color='red')
dot.node('B', 'End', shape='box', color='blue')
dot.node('A', 'B', 'Transition', color='green')
dot.edge(
dot
Creating Subgraphs
Code
= graph()
dot
with dot.subgraph(name='cluster_0') as c:
'A', 'Node A')
c.node('B', 'Node B')
c.node('A', 'B')
c.edge(='Subgraph 1')
c.attr(label
with dot.subgraph(name='cluster_1') as c:
'C', 'Node C')
c.node('D', 'Node D')
c.node('C', 'D')
c.edge(='Subgraph 2')
c.attr(label
'A', 'C')
dot.edge(
dot
Directed Acyclic Graph (DAG)
Code
= graph()
dag
'1', 'Step 1')
dag.node('2', 'Step 2')
dag.node('3', 'Step 3')
dag.node('1', '2')
dag.edge('2', '3')
dag.edge(
dag
Graph with Attributes:
Code
from graphviz import Digraph
= graph()
dot
'node', shape='circle')
dot.attr('A')
dot.node('B')
dot.node('C')
dot.node('D')
dot.node(
'A', 'B')
dot.edge('A', 'C')
dot.edge('B', 'D')
dot.edge('C', 'D')
dot.edge(
='Graph with Attributes', fontsize='20')
dot.attr(label dot
Flowchart
Code
= graph()
flowchart ='rounded,filled',
flowchart.graph_attr.update(style='TB',
rankdir
)'Start', 'Start', shape='ellipse', style='filled', color='lightgrey')
flowchart.node('A', 'Action A', shape='box')
flowchart.node('B', 'Action B', shape='box')
flowchart.node('C', 'Action C', shape='diamond')
flowchart.node('End', 'End', shape='ellipse', style='filled', color='lightgrey')
flowchart.node(
'Start', 'A')
flowchart.edge('A', 'B')
flowchart.edge('B', 'C')
flowchart.edge('C', 'End')
flowchart.edge(
flowchart
Tree Diagram
Code
from graphviz import Digraph
= graph()
tree ='rounded,filled',
tree.graph_attr.update(style='TB',
rankdir
)'A', 'Root')
tree.node('B', 'Child B')
tree.node('C', 'Child C')
tree.node('D', 'Child D')
tree.node('E', 'Child E')
tree.node(
'A', 'B')
tree.edge('A', 'C')
tree.edge('B', 'D')
tree.edge('B', 'E')
tree.edge(
tree
CNN
Code
= graph(comment='CNN Architecture')
dot
# Define nodes
'I', 'Input Layer\n(32x32x3)')
dot.node('C1', 'Conv Layer 1\n(28x28x32)')
dot.node('P1', 'Pooling Layer 1\n(14x14x32)')
dot.node('C2', 'Conv Layer 2\n(10x10x64)')
dot.node('P2', 'Pooling Layer 2\n(5x5x64)')
dot.node('F', 'Fully Connected Layer\n(1024)')
dot.node('O', 'Output Layer\n(10)')
dot.node(
# Define edges
'I', 'C1', label='Conv\n(5x5, 32)')
dot.edge('C1', 'P1', label='MaxPool\n(2x2)')
dot.edge('P1', 'C2', label='Conv\n(5x5, 64)')
dot.edge('C2', 'P2', label='MaxPool\n(2x2)')
dot.edge('P2', 'F', label='Flatten')
dot.edge('F', 'O', label='Dense')
dot.edge(
# Render the graph
dot
Advanced
Code
= '#000000'
black
= graph('A', filename='Data/plan', engine = 'dot')
g
with g.subgraph(name='clusterBusiness') as v:
='Business/Marketing/Finance', shape = 'doublecircle', fillcolor=g.primary, fontcolor=g.fifth)
v.attr(label'node', shape = 'box', fillcolor=g.secondary, fontcolor=g.fifth, penwidth = '0')
v.attr('Drone', 'Drone')
v.node('Laser', 'Laser')
v.node(
with g.subgraph(name='clusterIntern') as b:
='Intership', shape = 'doublecircle', fillcolor=g.primary, fontcolor=g.fifth)
b.attr(label'node', shape = 'box', fillcolor=g.secondary, fontcolor=g.fifth)
b.attr('phisaver', 'Phisaver')
b.node(
'Project',
g.node('''<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="10" CELLPADDING="10" STYLE = "rounded">
<TR><TD PORT="f" BORDER="0" STYLE = "rounded" WIDTH="100" >Project</TD></TR>
<TR><TD PORT="InfoAI" STYLE = "rounded" BGCOLOR="#fcbf49" >Information AI</TD></TR>
<TR><TD PORT="3D" STYLE = "rounded" BGCOLOR="#fcbf49" >3D vision- modeling AI</TD></TR>
<TR><TD PORT="stocks" STYLE = "rounded" BGCOLOR="#fcbf49" >Trading Algo</TD></TR>
</TABLE>>''',
=g.primary,
fillcolor= '0')
penwidth
'FASTAI:e', 'Thesis:w')
g.edge('Thesis:e', 'Project:3D:w')
g.edge(
'phisaver:e', 'Flutter:w')
g.edge('phisaver:e', 'Forecasting:w')
g.edge('phisaver:e', 'ML:w')
g.edge(
'Forecasting:e', 'Project:stocks:w')
g.edge('Flutter:e', 'Project:3D:w')
g.edge('Flutter:e', 'Thesis:w')
g.edge(
'ML:e', 'Project:w')
g.edge(
'Laser:e','Project:w')
g.edge('Laser:e', 'Manufacturer:w')
g.edge(
'Drone:e','Project:w')
g.edge('Drone:e', 'Drone:w')
g.edge('Drone:e', 'Manufacturer:w')
g.edge(
format='svg', cleanup=False)
g.render(
g