@@ -823,15 +823,19 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
823
823
"""This function takes in a graph and a partition and makes a figure that
824
824
has each node labeled according to its partition assignment"""
825
825
826
+
827
+ write_labels = False
826
828
nnod = g .number_of_nodes ()
827
829
828
830
if nod_labels == None :
829
831
nod_labels = dict (zip (range (nnod ),range (nnod )))
830
832
else :
831
833
nod_labels = dict (zip (range (nnod ),nod_labels ))
832
834
833
- #nod_labels = array_to_string(nod_labels)
834
835
836
+ plt .figure ()
837
+ plt .subplot (111 )
838
+ plt .axis ('off' )
835
839
836
840
if pos == None :
837
841
pos = nx .circular_layout (g )
@@ -846,31 +850,19 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
846
850
847
851
if niter < len (col ):
848
852
if within_mod == 'none' : #note: assumes part_coeff also there
849
- for v in val :
850
- if les_dam != 'none' :
851
- plt .scatter (pos [v ][0 ],pos [v ][1 ],s = 100 * les_dam [v ],c = 'orange' ,marker = (4 ,1 ,0 ))
852
853
nx .draw_networkx_nodes (g ,pos ,nodelist = list (val ),node_color = col [niter ],node_size = 50 )
853
854
else :
854
855
for v in val :
855
- if les_dam != 'none' :
856
- plt .scatter (pos [v ][0 ],pos [v ][1 ],s = 500 * les_dam [v ],c = 'orange' ,marker = (4 ,1 ,0 ))
857
-
858
856
if within_mod [v ] > 1 :
859
857
nx .draw_networkx_nodes (g ,pos ,nodelist = [v ],node_color = col [niter ],node_size = part_coeff [v ] * 500 + 50 ,node_shape = 's' ,linewidths = 2 )
860
858
else :
861
859
nx .draw_networkx_nodes (g ,pos ,nodelist = [v ],node_color = col [niter ],node_size = part_coeff [v ] * 500 + 50 ,node_shape = 'o' ,linewidths = 0.5 )
862
860
else :
863
861
#print 'out of colors!!'
864
862
if within_mod == 'none' : #note: assumes part_coeff also there
865
- for v in val :
866
- if les_dam != 'none' :
867
- plt .scatter (pos [v ][0 ],pos [v ][1 ],s = 100 * les_dam [v ],c = 'orange' ,marker = (4 ,1 ,0 ))
868
863
nx .draw_networkx_nodes (g ,pos ,nodelist = list (val ),node_color = col2 [niter ],node_size = 50 )
869
864
else :
870
865
for v in val :
871
- if les_dam != 'none' :
872
- plt .scatter (pos [v ][0 ],pos [v ][1 ],s = 500 * les_dam [v ],c = 'orange' ,marker = (4 ,1 ,0 ))
873
-
874
866
if within_mod [v ] > 1 :
875
867
nx .draw_networkx_nodes (g ,pos ,nodelist = [v ],node_color = col2 [niter ],node_size = part_coeff [v ] * 500 + 50 ,node_shape = 's' ,linewidths = 2 )
876
868
else :
@@ -901,11 +893,20 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
901
893
else :
902
894
nx .draw_networkx_edges (g ,pos ,edgelist = edge_list_within ,edge_color = col2 [niter ])
903
895
niter += 1
904
-
905
- nx . draw_networkx_labels ( g , pos , nod_labels , font_size = 6 )
896
+
897
+
906
898
#nx.draw_networkx_edges(g,pos,edgelist=nx.edges(g))
907
899
nx .draw_networkx_edges (g ,pos ,edgelist = edge_list_between ,edge_color = 'k' )
908
-
900
+ if write_labels :
901
+ nx .draw_networkx_labels (g ,pos ,nod_labels ,font_size = 6 )
902
+
903
+ #add loop for damage labels
904
+ if les_dam != 'none' :
905
+ for m ,val in part .iteritems ():
906
+ for v in val :
907
+ if les_dam [v ] > 0 :
908
+ plt .scatter (pos [v ][0 ],pos [v ][1 ],s = 500 * les_dam [v ]+ 100 ,c = 'orange' ,marker = (4 ,1 ,0 ))
909
+
909
910
plt .title (title )
910
911
#plt.savefig(fname)
911
912
#plt.close()
0 commit comments