Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. from networkx import *
  2.  
  3. #元データ
  4. data = [["A","B"],["A","C"],["C","B"],["D","C"],["D","E"],["C","E"],["E","F"]]
  5.  
  6. #ノードの構築
  7. G = nx.Graph()
  8. for p in list(set([r[0] for r in data] + [r[1] for r in data])):
  9. G.add_node(p)
  10.  
  11. #エッジの構築
  12. for d in data:
  13. G.add_edge(d[0],d[1])
  14.  
  15. #描画
  16. pos = nx.spring_layout(G)
  17. nx.draw_networkx_nodes(G, pos, node_size=1200,node_color="white")
  18. nx.draw_networkx_edges(G, pos)
  19. nx.draw_networkx_labels(G, pos)
  20. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement