1

I want to draw a Multi layer network by using Python. The expected graph likes this: enter image description here

I want to use Python's Multinetx to draw this network. This is my command:

import Multinetx as mx
import matplotlib.pyplot as plt
mg = mx.MultilayerGraph(list_of_layers=[mst_pearson,mst_kendall,mst_tail])
plt.axis('off')
pos = mx.get_position(mg,mx.fruchterman_reingold_layout(mst_pearson),
                  layer_vertical_shift=0.2,
                  layer_horizontal_shift=0.0,
                  proj_angle=47)
mx.draw_networkx(mg,pos=pos,node_size=50,with_labels=False,
             edge_color=[mg[a][b]['weight'] for a,b in mg.edges()],
             edge_cmap=plt.cm.jet_r)
plt.show()

mst_pearson,mst_kendall,mst_tail are my original networks, I want to use them to establish a three-layers multilayer network. But the error is that:

KeyError                                  Traceback (most recent call last)
<ipython-input-9-560c2e877b57> in <module>()
      4          layer_vertical_shift=0.2,
      5          layer_horizontal_shift=0.0,                                                     
----> 6                       proj_angle=50)
  7 mx.draw_networkx(mg,pos=pos,node_size=50,with_labels=False,
  8                                  edge_color=[mg[a][b]['weight'] for a,b in mg.edges()],

 C:\Users\wenzh\multinetx\draw.py in get_position(G, base_pos, 
       layer_vertical_shift, layer_horizontal_shift, proj_angle)
      70 
      71     for j in range(N):
 ---> 72         pos[j][0] *= math.cos(proj_angle)
      73         pos[j][1] *= math.sin(proj_angle)
      74 

 KeyError: 0

What is that error mean? How could I fix it?

taylor
  • 457
  • 1
  • 5
  • 17
  • 1
    From the error message, it looks like `Multinex` expects node IDs to be consecutive integers (i.e. `range(0,N)`). I would wager a guess that the nodes in your network are not integers. – Paul Brodersen Mar 22 '18 at 16:43
  • Yes,the network's nodes'ID are not integer,they are string. – taylor Mar 24 '18 at 02:23

0 Answers0