如何更改网络中节点的颜色? [英] How to change color of nodes in a network?
本文介绍了如何更改网络中节点的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变A
列中节点的颜色:
I would like to change the color of nodes within the column A
:
A B Score Value
0 user1 test1 6.6 A
1 user1 user241 3.2 AA
2 user241 test1 4.8 B
3 user12 test4 3.1 C
4 user1 user23 2.9 A
我使用 mnet 创建网络:
To create the network I am using mnet:
from pymnet import *
import matplotlib.pyplot as plt
mnet = MultilayerNetwork(aspects=1)
for index in df.index:
mnet[df.loc[index, 'A'], df.loc[index, 'B'],'friendship','friendship'] = 1
fig=draw(mnet, show=True, figsize=(25,30))
我想我应该在 draw()
中改变颜色,但我没有命令.无论使用哪种颜色,重要的是A
中的所有用户都可以具有相同的颜色(与B
中的不同).A
中的某些用户可能也在 B
中.
I think I should change the color within draw()
, but I do not not the command. No matter which color should be used, as what it is important is that all the users in A
can have the same color (different from that in B
). Some user within A
may be also in B
.
我会做这样的事情:
for node in mnet:
if node in df["A"].values:
colors.append("red")
else: colors.append("green")
但是我不知道如何在fig
中添加这样的信息.
But I do not know how to add such info in fig
.
推荐答案
根据 pymnet.draw(), nodeColorDict
是一个以节点层为键的字典.
According to pymnet.draw(), nodeColorDict
is a dictionary keyed by node-layer.
colors = {}
for node in mnet.iter_node_layers():
if node[0] in df["A"].values:
colors.update({node: "red"})
else:
colors.update({node: "green"})
fig = draw(mnet, show=True, figsize=(25,30), nodeColorDict=colors)
这篇关于如何更改网络中节点的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文