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).
Diese Übung ist Teil des Kurses
Intermediate Network Analysis in Python
Anleitung zur Übung
- Plot the degree centrality distribution of the original graph
G, using thedegree_centralityfunction from the bipartite module:nx.bipartite.degree_centrality(). It takes in two arguments: The graphG, and one of the node lists (peopleorclubs). - Plot the degree centrality distribution of the
peopleGgraph, using the normal/non-bipartitedegree_centralityfunction from NetworkX:nx.degree_centrality(). - Plot the degree centrality distribution of the
clubsGgraph, using the normal/non-bipartitedegree_centralityfunction from NetworkX:nx.degree_centrality().
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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()