Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. G = nx.Graph()
  2. positions = {}
  3. coordinates = [
  4. [0, 4],
  5. [-4, 3],
  6. [4, 3],
  7. [-6, 2],
  8. [-2, 2],
  9. [2, 2],
  10. [6, 2],
  11. [-7, 1],
  12. [-5, 1],
  13. [-3, 1],
  14. [-1, 1],
  15. [1, 1],
  16. [3, 1],
  17. [5, 1],
  18. [7, 1],
  19. [4, 0],
  20. [6, 0],
  21. [8, 0]
  22. ]
  23. parents = [0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 13, 14, 14]
  24. for index in range(len(parents)):
  25. G.add_node(index)
  26. G.add_edge(index, parents[index])
  27. positions[index] = coordinates[index]
  28. nx.draw(G, positions, node_size = 1000)
  29. labels = {
  30. 0: '0',
  31. 1: '1',
  32. 2: '2',
  33. 3: '3',
  34. 4: '4',
  35. 5: '5',
  36. 6: '6',
  37. 7: 'tx1',
  38. 8: 'tx2',
  39. 9: 'tx3',
  40. 10: 'tx4',
  41. 11: 'tx5',
  42. 12: 'tx6',
  43. 13: '13',
  44. 14: '14',
  45. 15: 'tx7',
  46. 16: 'tx8',
  47. 17: 'tx9'
  48. }
  49. nx.draw_networkx_labels(G, positions, labels = labels)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement