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.

mat_tonxgraph.py 885B

5 years ago
1234567891011121314151617181920212223
  1. import numpy as np
  2. import networkx as nx
  3. import matplotlib.pyplot as plt
  4. import scipy.io as sp
  5. def graph_save(G, dir, i):
  6. pos = nx.spring_layout(G)
  7. nx.draw_networkx_nodes(G, pos, cmap=plt.get_cmap('jet'),
  8. node_color='b', node_size=300)
  9. nx.draw_networkx_labels(G, pos)
  10. nx.draw_networkx_edges(G, pos, edgelist=G.edges(), arrows=False)
  11. plt.savefig('{}.png'.format(i))
  12. plt.close()
  13. LENGTH = 6
  14. # missing_dir = 'testgraph_12_,.mat_0_3_miss.txt'
  15. for i in range(0, 11):
  16. recons_dir = 'out/graphed_{}.mat'.format(i)
  17. adj_matrix_orig = sp.loadmat(recons_dir)['original_data'].A
  18. adj_matrix_p = sp.loadmat(recons_dir)['out_data'].A
  19. graph_orig = nx.convert_matrix.from_numpy_matrix(adj_matrix_orig)
  20. graph_p = nx.convert_matrix.from_numpy_matrix(adj_matrix_p)
  21. graph_save(graph_orig,'', i+1)
  22. graph_save(graph_p,'', -(i+1))