Plot degree centrality on projection
Here, you're going to compare the degree centrality distributions for each of the following graphs: the original graph G
, the people graph projection peopleG
, and the clubs graph projection clubsG
. This will reinforce the difference in degree centrality score computation between bipartite and unipartite versions of degree centrality metrics. The node lists people
and clubs
have been pre-loaded for you.
Recall from the video that the bipartite functions require passing in a container of nodes, but will return all degree centrality scores nonetheless. Remember also that degree centrality scores are stored as dictionaries (mapping node to score).
This exercise is part of the course
Intermediate Network Analysis in Python
Exercise instructions
- Plot the degree centrality distribution of the original graph
G
, using thedegree_centrality
function from the bipartite module:nx.bipartite.degree_centrality()
. It takes in two arguments: The graphG
, and one of the node lists (people
orclubs
). - Plot the degree centrality distribution of the
peopleG
graph, using the normal/non-bipartitedegree_centrality
function from NetworkX:nx.degree_centrality()
. - Plot the degree centrality distribution of the
clubsG
graph, using the normal/non-bipartitedegree_centrality
function from NetworkX:nx.degree_centrality()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import matplotlib.pyplot as plt
# Plot the degree centrality distribution of both node partitions from the original graph
plt.figure()
original_dc = ____
# Remember that you can directly plot dictionary values.
plt.hist(____, alpha=0.5)
plt.yscale('log')
plt.title('Bipartite degree centrality')
plt.show()
# Plot the degree centrality distribution of the peopleG graph
plt.figure()
people_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of people partition')
plt.show()
# Plot the degree centrality distribution of the clubsG graph
plt.figure()
clubs_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of clubs partition')
plt.show()