In [1]:
import networkx as nx
In [2]:
G = nx.DiGraph()
# Add nodes with the node attribute "bipartite"
people = ["Paul Anderson", "Dennis Sun", "Alexander Dekhtyar","Jean Davidson"]
departments = ["Computer Science and Software Engineering","Statistics","Biology"]
programs = ["CDSM in Data Science","CDSM in Bioinformatics"]
G.add_nodes_from(people, multipartite="people")
G.add_nodes_from(departments, multipartite="departments")
G.add_nodes_from(programs, multipartite="programs")
# Add edges only between nodes of opposite node sets
department_affiliation = [
("Paul Anderson","Computer Science and Software Engineering"),
("Dennis Sun","Statistics")
]
G.add_edges_from(department_affiliation)
In [5]:
%matplotlib inline
import matplotlib.pyplot as plt
pos = nx.random_layout(G) # positions for all nodes
# nodes
nx.draw_networkx_nodes(G, pos, node_size=700)
# edges
nx.draw_networkx_edges(G, pos)
# labels
nx.draw_networkx_labels(G, pos, font_size=20, font_family='sans-serif')
plt.axis('off')
plt.show()
In [ ]: