随时间变化的边数量
现在,您将练习绘制其他随时间变化的图统计量。我们先从一个更简单的练习开始。首先,请绘制随时间变化的边数量。
为此,您将创建一个列表,记录每个月的边数量。该列表的索引对应自第 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()