2014-02-17 40 views
0

我正在用networkx绘制大图,并且当图大时我遇到了问题。对于小图,一切正常,但对于大图(1k节点),分配颜色和大小似乎失败。 这是有问题的代码段使用matplotlib绘制大图时节点大小和颜色的错误

H=nx.connected_component_subgraphs(G)[0] 
d=nx.degree(H) 
b=nx.eigenvector_centrality(H) 
pos2=nx.spring_layout(H,scale=2) 

labels={} 
colors={} 
dim={} 

for n in H.nodes(): 
    i=0 
    for v in b: 
     if v==n: 
      break 
     i+=1 
    colors[n]=b.values()[i] 
    j=0 
    for w in d: 
     if w==n: 
      break 
     j+=1 
    dim[n]=d.values()[j]*40 

    k=0 
    for z in range(2): 
     if n in sorted(b.items(), key=lambda x:x[1],reverse=True)[z]: 
      labels[n]=n 


nx.draw(H, 
      pos2, 
      with_labels=False, 
      node_size=dim.values(), 
      node_color=colors.values(), 
      cmap=plt.cm.Reds, 
      vmin=min(b.values()), 
      vmax=max(b.values()) 
) 

,因为我没有足够的声誉,我不能发表图片,但是当我说,它没有我的意思是(部分)低的连接节点是更大然后具有高连接性的节点,并且颜色也是如此。

想知道它是怎么回事?

enter image description here enter image description here

+0

把它们放在一些地方,并包括一个链接。高级用户并将其编辑到您的帖子中。 – tacaswell

+0

这里是小图示例https://www.dropbox.com/s/sgwiop394cgik7j/ex1.png 和她的大变焦 https://www.dropbox.com/s/paustbt0wci75cl/ex2 .png – imabug

+0

所以SO似乎不喜欢下拉框链接..... – tacaswell

回答

0

传递关键字节点列表=你想要绘制的节点。然后使用相同的顺序在列表中将颜色和大小设置为node_color和node_size参数。

nodes = H.nodes() 

nx.draw(H, pos2, nodelist=nodes, 
     node_size = [dim[n] for n in nodes], 
     node_color= [colors[n] for n in nodes], 
     cmap=plt.cm.Reds, 
     vmin=min(b.values()), 
     vmax=max(b.values()), 
     with_labels=False 
) 
相关问题