【发布时间】:2020-06-11 02:10:41
【问题描述】:
我有一个数据框,其中包含 source: person 1、target: person 2 和 in_rewards_program: binary。
我使用 pyvis 包创建了一个网络"
got_net = Network(notebook=True, height="750px", width="100%")
# got_net = Network(notebook=True, height="750px", width="100%", bgcolor="#222222", font_color="white")
# set the physics layout of the network
got_net.barnes_hut()
got_data = df
sources = got_data['source']
targets = got_data['target']
# create graph using pviz network
edge_data = zip(sources, targets)
for e in edge_data:
src = e[0]
dst = e[1]
#add nodes and edges to the graph
got_net.add_node(src, src, title=src)
got_net.add_node(dst, dst, title=dst)
got_net.add_edge(src, dst)
neighbor_map = got_net.get_adj_list()
# add neighbor data to node hover data
for node in got_net.nodes:
node["title"] += " Neighbors:<br>" + "<br>".join(neighbor_map[node["id"]])
node["value"] = len(neighbor_map[node["id"]]) # this value attrribute for the node affects node size
got_net.show("test.html")
我想根据in_rewards_program 中的值添加节点颜色不同的功能。如果源节点为 0,则将节点设为红色,如果源节点为 1,则将其设为蓝色。我不知道该怎么做。
【问题讨论】: