2017-07-02 115 views
0

如何使用networkx獲取節點的邊界線?見下圖。我的問題是由於白色節點。無論顏色如何,我都想表達自己的形狀。通過與其他人比較查看節點4。節點在python網絡中沒有邊界x

代碼示例

import networkx as nx 
import matplotlib.pyplot as plot 

g= {1: [2, 3], 
    2: [2, 3, 4], 
    3: [1, 2], 
    4: [2]} 

graph= nx.Graph() 

for v in g: 
    graph.add_node(v) 

for v in g: 
    for u in g[v]: 
     graph.add_edge(v, u) 

nx.draw_networkx(graph, node_color=['r', 'r', 'r', 'w'], node_shape='o') 

plot.axis('off') 
plot.show() 

輸出

enter image description here

+0

https://stackoverflow.com/q/22716161/2966723 – Joel

+0

的[如何才能修改節點networkx的輪廓顏色?(可能的複製https://stackoverflow.com/questions/22716161 /如何燦酮 - 修改 - 的外形色對的一節點功能於networkx) – Joel

回答

0

我知道了。

ax= plot.gca() 
ax.collections[0].set_edgecolor("#000000") 

添加上面的行以設置節點邊緣的顏色。

import networkx as nx 
import matplotlib.pyplot as plot 

g= {1: [2, 3], 
    2: [2, 3, 4], 
    3: [1, 2], 
    4: [2]} 

graph= nx.Graph() 

for v in g: 
    graph.add_node(v) 
    for u in g[v]: 
     graph.add_edge(v, u) 

nx.draw_networkx(graph, node_color=['r', 'r', 'r', 'w'], node_shape='o') 

ax= plot.gca() 
ax.collections[0].set_edgecolor("#000000") 

plot.axis('off') 
plot.show()