开始使用免费开始使用

Degree centrality distribution

The degree of a node is the number of neighbors that it has. The degree centrality is the number of neighbors divided by all possible neighbors that it could have. Depending on whether self-loops are allowed, the set of possible neighbors a node could have could also include the node itself.

The nx.degree_centrality(G) function returns a dictionary, where the keys are the nodes and the values are their degree centrality values.

The degree distribution degrees you computed in the previous exercise using the list comprehension has been pre-loaded.

本练习是课程的一部分

Introduction to Network Analysis in Python

查看课程

练习说明

  • Compute the degree centrality of the Twitter network T.
  • Using plt.hist(), plot a histogram of the degree centrality distribution of T. This can be accessed using list(deg_cent.values()).
  • Plot a histogram of the degree distribution degrees of T. This is the same list you computed in the last exercise.
  • Create a scatter plot with degrees on the x-axis and the degree centrality distribution list(deg_cent.values()) on the y-axis.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import matplotlib.pyplot
import matplotlib.pyplot as plt

# Compute the degree centrality of the Twitter network: deg_cent
deg_cent = ____

# Plot a histogram of the degree centrality distribution of the graph.
plt.figure()
____
plt.show()

# Plot a histogram of the degree distribution of the graph
plt.figure()
____
plt.show()

# Plot a scatter plot of the centrality distribution and the degree distribution
plt.figure()
____
plt.show()
编辑并运行代码