Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pymnet - creating a multilayered network visualisation

I have the code below to load the data:

from pymnet import * 
import pandas as pd 

nodes_id = ['a',    'b',    'c',    'd',    'e',    'f',    'g',    1,  2,  3,  'aa',   'bb',   'cc']
layers = [1,    1,  1,  1,  1,  1,  1,  2,  2,  2,  3,  3,  3]
nodes = {'nodes': nodes_id, 'layers': layers}
df_nodes = pd.DataFrame(nodes)

to = ['b',  'c',    'd',    'f',    1,  2,  3,  'bb',    'cc',  2,  3,  'a',    'g']
from_edges = ['a',  'a',    'b',    'e',    'a',    'b',    'e',    'aa',   'aa',   'aa', 1, 2, 3]
edges = {'to': to, 'from': from_edges}
df_edges = pd.DataFrame(edges)

I am attempting to use pymnet as a package to create a multi-layered network. (http://www.mkivela.com/pymnet/)

Does anybody know how to create a 3 layered network visualisation using this diagram? The tutorials seem to add nodes one at a time and it is unclear how to use a nodes and edges dataframe for this purpose. The layer groups are provided in the df_nodes.

Thanks

like image 615
zamad27 Avatar asked Oct 09 '18 12:10

zamad27


1 Answers

I've wondered the same, have a look at this post: https://qiita.com/malimo1024/items/499a4ebddd14d29fd320 Use the format of this: mnet[from_node,to_node_2,layer_1,layer_2] = 1 to add edges (inter/intra). For example:

from pymnet import *
import matplotlib.pyplot as plt
%matplotlib inline

mnet = MultilayerNetwork(aspects=1)
mnet['sato','tanaka','work','work'] = 1
mnet['sato','suzuki','friendship','friendship'] = 1
mnet['sato','yamada','friendship','friendship'] = 1
mnet['sato','yamada','work','work'] = 1
mnet['sato','sato','work','friendship'] = 1
mnet['tanaka','tanaka','work','friendship'] = 1
mnet['suzuki','suzuki','work','friendship'] = 1
mnet['yamada','yamada','work','friendship'] = 1
fig=draw(mnet)

enter image description here

like image 151
Nengchi Te Avatar answered Nov 14 '22 23:11

Nengchi Te