Skip to content

Commit 28b1948

Browse files
author
Caterina Gratton
committed
Added ability to take away labels in modularity plot_partitions.
1 parent db1a70c commit 28b1948

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

brainx/modularity.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -823,15 +823,19 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
823823
"""This function takes in a graph and a partition and makes a figure that
824824
has each node labeled according to its partition assignment"""
825825

826+
827+
write_labels = False
826828
nnod = g.number_of_nodes()
827829

828830
if nod_labels == None:
829831
nod_labels = dict(zip(range(nnod),range(nnod)))
830832
else:
831833
nod_labels = dict(zip(range(nnod),nod_labels))
832834

833-
#nod_labels = array_to_string(nod_labels)
834835

836+
plt.figure()
837+
plt.subplot(111)
838+
plt.axis('off')
835839

836840
if pos == None:
837841
pos=nx.circular_layout(g)
@@ -846,31 +850,19 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
846850

847851
if niter <len(col):
848852
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))
852853
nx.draw_networkx_nodes(g,pos,nodelist=list(val),node_color=col[niter],node_size=50)
853854
else:
854855
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-
858856
if within_mod[v] > 1:
859857
nx.draw_networkx_nodes(g,pos,nodelist=[v],node_color=col[niter],node_size=part_coeff[v] * 500+50,node_shape='s',linewidths=2)
860858
else:
861859
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)
862860
else:
863861
#print 'out of colors!!'
864862
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))
868863
nx.draw_networkx_nodes(g,pos,nodelist=list(val),node_color=col2[niter],node_size=50)
869864
else:
870865
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-
874866
if within_mod[v] > 1:
875867
nx.draw_networkx_nodes(g,pos,nodelist=[v],node_color=col2[niter],node_size=part_coeff[v] * 500+50,node_shape='s',linewidths=2)
876868
else:
@@ -901,11 +893,20 @@ def plot_partition(g,part,title,fname='figure',nod_labels = None, pos = None,
901893
else:
902894
nx.draw_networkx_edges(g,pos,edgelist=edge_list_within,edge_color=col2[niter])
903895
niter += 1
904-
905-
nx.draw_networkx_labels(g,pos,nod_labels,font_size=6)
896+
897+
906898
#nx.draw_networkx_edges(g,pos,edgelist=nx.edges(g))
907899
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+
909910
plt.title(title)
910911
#plt.savefig(fname)
911912
#plt.close()

0 commit comments

Comments
 (0)