整数パーティションのコードを作成し、各ノードがパーティションであるグラフを作成しています。グラフ内のノードに {2,1,1}、{1,1,1,1}、{2,2} などのパーティション要素でラベルを付けたいと思います。
だから、networkxでノードにラベルを付ける方法を知りたいです。
ノードにラベルを付けるためのコードは既に見ましたが、わかりませんでした。コードを以下に示します。
nx.draw_networkx_nodes(G,pos,
nodelist=[0,1,2,3],
node_color='r',
node_size=500,
alpha=0.8)
しかし、私が望むのは、すでに構築されたグラフの個々のノードにラベルを付けることです!
ここでコードを提供しているので、理解を深めることができます。
import networkx as nx
from matplotlib import pylab as pl
def partitions(num):
final=[[num]]
for i in range(1,num):
a=num-i
res=partitions(i)
for ele in res:
if ele[0]<=a:
final.append([a]+ele)
return final
def drawgraph(parlist):
#This is to draw the graph
G=nx.Graph()
length=len(parlist)
print "length is %s\n" % length
node_list=[]
for i in range(1,length+1):
node_list.append(i)
G.add_cycle(node_list)
nx.draw_circular(G)
pl.show()
私を助けてください。
どうもありがとうございました