2017-09-09 21 views
2

network add_nodesを使って作成したノードのフォントを変更するにはどうすればいいですか?networkx - pythonのadd_nodesのフォントを変更します

コード:

g=nx.Graph() 
g=nx.Graph() 
node=0 
for i in range(len(newinput)): 
    for j in range(0,len(newinput[i])): 
     g.add_node(node,size=1,pos=(newinput[i][j][0],newinput[i][j][1])) 
     node+=1 

    pos = nx.spring_layout(g) 
    pos = nx.get_node_attributes(g, 'pos') 

conn=0 
while conn<node-1: 
    g.add_edge(conn, conn + 1) 
    conn+=1 
nx.draw(g,pos) 
pylab.show() 

enter image description here

私は上記の画像のように、大きな赤い丸で示したラインの端点を望んでいません。

add_nodeでsize = 1属性を確認しましたが、機能しません。

+0

2質問:1)あなたは 'newinput'があるかを示すことはできますか?人々がデータを自分で生成する必要がないように、データでコードを演奏すると便利です。 2)そして、頂点のない辺を表示したいのですか、別の形や色の頂点を描くことを意味していますか? – TuanDT

+0

@ Tuan333:newinputはxとy座標を持つlist [list []]です。そして、ノードだけでエッジを表示したい。 私はこれを行うことができます:) - 'nx.draw(g、pos、node_size = 0.5)'を使用すると答えとして送信されます。ご協力いただきありがとうございます。 –

答えて

0

draw関数のnode_size属性でこれを解決できます。

nx.draw(g,pos,node_size=0.5)

コード:

g=nx.Graph() 
node=0 
for i in range(len(newinput)): 
    for j in range(0,len(newinput[i])): 
     g.add_node(node,size=1,pos=(newinput[i][j][0],newinput[i][j][1])) 
     node+=1 

    pos = nx.spring_layout(g) 
    pos = nx.get_node_attributes(g, 'pos') 

conn=0 
while conn<node-1: 
    g.add_edge(conn, conn + 1) 
    conn+=1 
nx.draw(g,pos,node_size=0.5) 
pylab.show() 

新しい出力: enter image description here

関連する問題