Computational-Content-Analysis-2020 / Readings-Responses-Spring

Repository for organizing orienting, exemplary and fundament readings, and posting responses.
0 stars 0 forks source link

Multilayer network #52

Open BENFREDJRima-34 opened 3 years ago

BENFREDJRima-34 commented 3 years ago

Hello, I want to build A multilayer network ( 2 layers) with this 2 graph,

import numpy as np import matplotlib.pyplot as plt import networkx as nx

nx.version """ graph1"""

Graph1 = nx.DiGraph() Graph1.add_node(0,RA=0.8,CPX=0.05,Comp=1 ) Graph1.add_node(1) Graph1.add_node(2) Graph1.add_node(3)

Graph1.add_nodes_from(range(4) ) # adds nodes 0, 1

add edge from node 0 to node 1

Graph1.add_edges_from([(0, 1, {"color": "red", }), (2, 3, {"color": "red" })]) Graph1.add_edges_from([(0, 3, {"color": "red", }), (2, 0, {"color": "red" })]) Graph1.add_edges_from([(0, 2, {"color": "red", }), (0, 3, {"color": "red" })]) Graph1.add_edges_from([(2, 3, {"color": "red", }), (1, 3, {"color": "red" })])

draws the graph to pyplot axes

nx.draw(Graph1, with_labels=True, font_weight='bold')

plt.show()

""" graph2""" Graph2 = nx.DiGraph() Graph2.add_node(4,RA=0.8,CPX=0.05,Comp=1 ) Graph2.add_node(5) Graph2.add_node(6) Graph2.add_node(7)

Graph2.add_nodes_from(range(4) ) # adds nodes 0, 1

add edge from node 0 to node 1

Graph2.add_edges_from([(5, 7, {"color": "red", }), (2, 3, {"color": "red" })]) Graph2.add_edges_from([(4, 6, {"color": "red", }), (2, 0, {"color": "red" })]) Graph2.add_edges_from([(7, 6, {"color": "red", }), (0, 3, {"color": "red" })]) Graph2.add_edges_from([(4, 5, {"color": "red", }), (1, 3, {"color": "red" })])

draws the graph to pyplot axes

nx.draw(Graph2, with_labels=True, font_weight='bold')

plt.show()