可视化 networkx
作者:互联网
前言:
参考资料:https://zhuanlan.zhihu.com/p/433680105
代码:
g = nx.Graph()
df_count = df['ID1'].value_counts().reset_index()
df_count.columns = ['ID', 'count']
dict_count = dict()
for index, row in df_count.iterrows():
dict_count[row['ID']] = row['count']
dict_color = dict()
for index, row in df.iterrows():
g.add_node(row['ID1'], label=row['Product1'], size=dict_count[row['ID1']]*10, color='#58D3F7')
g.add_node(row['ID2'], label=row['Product2'], size=dict_count[row['ID1']]*10, color='#58D3F7')
g.add_edge(row['ID1'], row['ID2'], width=row['Degree']*10, color='white')
nt = net.Network(height='700px', width='700px', bgcolor="black", font_color='white')
nt.from_nx(g)
nt.hrepulsion()
nt.show('旅游产品图谱.html')
display(HTML('旅游产品图谱.html'))
标签:count,color,ID1,df,dict,networkx,可视化,row 来源: https://www.cnblogs.com/welcome-to-future/p/16174708.html