You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

graph_show.py 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import networkx as nx
  2. import matplotlib.pyplot as plt
  3. import matplotlib.pylab as pl
  4. import matplotlib.gridspec as gridspec
  5. from matplotlib.pyplot import figure
  6. def graph_save(main_graphs, incomplete_graphs, completed_graphs, completed_graphs_with_training,
  7. name, path):
  8. # Create 2x2 sub plots
  9. gs = gridspec.GridSpec(2, 2)
  10. pl.figure()
  11. figure(num=None, figsize=(10, 10), dpi=80, facecolor='w', edgecolor='k')
  12. # main_graphs
  13. ax = pl.subplot(gs[0, 0]) # row 0, col 0
  14. pos = nx.spring_layout(main_graphs)
  15. nx.draw_networkx_nodes(main_graphs, pos, cmap=plt.get_cmap('jet'),
  16. node_color='b', node_size=500)
  17. nx.draw_networkx_labels(main_graphs, pos)
  18. nx.draw_networkx_edges(main_graphs, pos, edgelist=main_graphs.edges(), arrows=False)
  19. ax.set_yticklabels([])
  20. ax.set_xticklabels([])
  21. pl.title('Main')
  22. pl.plot()
  23. # incomplete_graphs
  24. ax = pl.subplot(gs[0, 1]) # row 0, col 0
  25. pos = nx.spring_layout(incomplete_graphs)
  26. nx.draw_networkx_nodes(incomplete_graphs, pos, cmap=plt.get_cmap('jet'),
  27. node_color='b', node_size=500)
  28. nx.draw_networkx_labels(incomplete_graphs, pos)
  29. nx.draw_networkx_edges(incomplete_graphs, pos, edgelist=incomplete_graphs.edges(), arrows=False)
  30. ax.set_yticklabels([])
  31. ax.set_xticklabels([])
  32. pl.title('Incomplete')
  33. pl.plot()
  34. # completed_graphs
  35. ax = pl.subplot(gs[1, 0]) # row 0, col 0
  36. pos = nx.spring_layout(completed_graphs)
  37. nx.draw_networkx_nodes(completed_graphs, pos, cmap=plt.get_cmap('jet'),
  38. node_color='b', node_size=500)
  39. nx.draw_networkx_labels(completed_graphs, pos)
  40. nx.draw_networkx_edges(completed_graphs, pos, edgelist=completed_graphs.edges(), arrows=False)
  41. ax.set_yticklabels([])
  42. ax.set_xticklabels([])
  43. pl.title('Completed without Training')
  44. pl.plot()
  45. # completed_graphs_with_training
  46. ax = pl.subplot(gs[1, 1]) # row 0, col 0
  47. pos = nx.spring_layout(completed_graphs_with_training)
  48. nx.draw_networkx_nodes(completed_graphs_with_training, pos, cmap=plt.get_cmap('jet'),
  49. node_color='b', node_size=500)
  50. nx.draw_networkx_labels(completed_graphs_with_training, pos)
  51. nx.draw_networkx_edges(completed_graphs_with_training, pos,
  52. edgelist=completed_graphs_with_training.edges(), arrows=False)
  53. ax.set_yticklabels([])
  54. ax.set_xticklabels([])
  55. pl.title('Completed with Training')
  56. pl.plot()
  57. # pl.show()
  58. plt.savefig(path + str(name + 1) + ".png", format="PNG")
  59. plt.close()
  60. def graph_show(G):
  61. pos = nx.spring_layout(G)
  62. nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap('jet'),
  63. node_color='b', node_size=500)
  64. nx.draw_networkx_labels(G, pos)
  65. nx.draw_networkx_edges(G, pos, edgelist=G.edges(), arrows=False)
  66. plt.show()
  67. if __name__ == '__main__':
  68. name = "small_grid_graphs"
  69. path = './results/' + name + '/'
  70. main_graphs = nx.read_gpickle(path + "main_graphs.dat")
  71. incomplete_graphs = nx.read_gpickle(path + "incomplete_graphs.dat")
  72. completed_graphs = nx.read_gpickle(path + "completed_graphs.dat")
  73. completed_graphs_with_training = nx.read_gpickle(path + "completed_graphs_with_training.dat")
  74. for i in range(len(main_graphs)):
  75. graph_save(main_graphs[i], incomplete_graphs[i],
  76. completed_graphs[i], completed_graphs_with_training[i], i, path)
  77. # i = 2
  78. # graph_save(main_graphs[i], incomplete_graphs[i],
  79. # completed_graphs[i], i, path)