Guest User

Untitled

a guest
Nov 21st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import networkx as nx
  2. import matplotlib.pyplot as plt
  3.  
  4. G = nx.MultiDiGraph()
  5.  
  6. G.add_edges_from([
  7. ('t1', 'c1'),
  8. ('t1', 'c2'),
  9. ('c1', 'c2'),
  10. ('c2', 'c1'),
  11. ('p2', 'c1'),
  12. ('c2', 'p2')
  13. ])
  14.  
  15. attrs = {'c1':{'key':100},
  16. 'c2':{'key':50},
  17. 't1':{'key':15},
  18. 'p2':{'key':30}}
  19. nx.set_node_attributes(G, attrs)
  20.  
  21. node_sizes = [a['key']*30 for n, a in G.nodes(data=True)]
  22.  
  23. # drawing ...
  24. pos = {key: [i*3, 0] for key, i in zip(attrs, range(len(attrs)))}
  25. print(pos)
  26. nx.draw(G, pos, with_labels=True,
  27. cmap=plt.get_cmap('jet'),
  28. node_size=node_sizes,
  29. arrows=True, arrowsize=40)
Add Comment
Please, Sign In to add comment