1import networkx as nx
2import pylab as plt
3from networkx.drawing.nx_agraph import graphviz_layout
4
5
6G = nx.DiGraph()
7G.add_node(1,level=1)
8G.add_node(2,level=2)
9G.add_node(3,level=2)
10G.add_node(4,level=3)
11
12G.add_edge(1,2)
13G.add_edge(1,3)
14G.add_edge(2,4)
15
16nx.draw(G, pos=graphviz_layout(G), node_size=1600, cmap=plt.cm.Blues,
17 node_color=range(len(G)),
18 prog='dot')
19plt.show()
20