Visualize the degree centrality distribution of the forums projection
This exercise is also to reinforce the concepts of degree centrality and projections. This time round, you'll plot the degree centrality distribution for the 'forum'
projection. Follow the same steps as in the previous exercise!
Diese Übung ist Teil des Kurses
Intermediate Network Analysis in Python
Anleitung zur Übung
- Get the nodes of the
'forum'
partition into a list calledforum_nodes
. - Create the forums nodes projection as a graph called
G_forum
. - Calculate the degree centrality of
G_forum
usingnx.degree_centrality()
. Store the result asdcs
. - Plot the histogram of degree centrality values.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Import necessary modules
import matplotlib.pyplot as plt
import networkx as nx
# Get the forums partition's nodes: forum_nodes
forum_nodes = [____]
# Create the forum nodes projection as a graph: G_forum
G_forum = ____
# Calculate the degree centrality using nx.degree_centrality: dcs
dcs = ____
# Plot the histogram of degree centrality values
____
plt.yscale('log')
plt.show()