0

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

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))

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.

I would do something like this:

for node in mnet:
    if node in df["A"].values:
        colors.append("red")
    else: colors.append("green")

But I do not know how to add such info in fig.

Math
  • 191
  • 2
  • 5
  • 19
  • I think it should be something to this: `nodeColorDict`. But I do not know how to assign a color if nodes are just present in the column. Reference: http://www.mkivela.com/pymnet/visualizing.html – Math Apr 05 '21 at 18:00

1 Answers1

1

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)
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52