开始使用免费开始使用

随时间变化的边数量

现在,您将练习绘制其他随时间变化的图统计量。我们先从一个更简单的练习开始。首先,请绘制随时间变化的边数量。

为此,您将创建一个列表,记录每个月的边数量。该列表的索引对应自第 1 个月以来经过的月数。

本练习是课程的一部分

Python 网络分析中级

查看课程

练习说明

  • 导入 matplotlib.pyplot,命名为 plt
  • 创建一个名为 edge_sizes 的列表,保存每个月的边数量。使用列表推导式实现:用迭代变量 g 遍历 Gs,输出表达式为 len(g.edges())
  • 绘制边数量的时间序列图。

交互式实操练习

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

# Import matplotlib
____

fig = plt.figure()

# Create a list of the number of edges per month
edge_sizes = [____]

# Plot edge sizes over time
plt.plot(____)
plt.xlabel('Time elapsed from first month (in months).') 
plt.ylabel('Number of edges')                           
plt.show() 
编辑并运行代码