隨時間變化的邊數
現在你要練習繪製其他會隨時間變動的圖形統計量。我們先從一個較簡單的練習開始:先畫出隨時間變化的邊數。
為此,你會建立一個串列,內容是每個月的邊數。此串列的索引對應自第一個月起所經過的月份數。
本練習屬於課程
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()