d080b400
Francisco Coelho
Paper draft: Exte...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import bnlearn as bn
import networkx as nx
import pydot
from networkx.drawing.nx_pydot import graphviz_layout
asia = bn.import_DAG("asia2.bif")
model = asia['model']
# DiGraph do networkx
G = nx.DiGraph()
for node in model.nodes:
G.add_node(node)
for edge in model.edges:
G.add_edge(edge[0], edge[1])
# objeto pydot
dot = pydot.Dot(graph_type='digraph')
for node in model.nodes:
dot.add_node(pydot.Node(node))
for edge in model.edges:
dot.add_edge(pydot.Edge(edge[0], edge[1]))
# defina o layout do grafo
pos = graphviz_layout(G, prog='dot')
# desenhe o grafo usando o networkx
nx.draw(G, pos, with_labels=True)
# renderize o grafo com o pydot
graph = pydot.graph_from_dot_data(dot.to_string())[0]
graph.write_png('graph_asia2.png')
|