LoslegenKostenlos loslegen

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

Kurs anzeigen

Anleitung zur Übung

  • Plot the degree centrality distribution of the original graph G, using the degree_centrality function from the bipartite module: nx.bipartite.degree_centrality(). It takes in two arguments: The graph G, and one of the node lists (people or clubs).
  • Plot the degree centrality distribution of the peopleG graph, using the normal/non-bipartite degree_centrality function from NetworkX: nx.degree_centrality().
  • Plot the degree centrality distribution of the clubsG graph, using the normal/non-bipartite degree_centrality function from NetworkX: nx.degree_centrality().

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

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()
Code bearbeiten und ausführen