開始使用免費開始

隨時間變化的邊數

現在你要練習繪製其他會隨時間變動的圖形統計量。我們先從一個較簡單的練習開始:先畫出隨時間變化的邊數。

為此,你會建立一個串列,內容是每個月的邊數。此串列的索引對應自第一個月起所經過的月份數。

本練習屬於課程

Python 網路分析進階

檢視課程

練習說明

  • matplotlib.pyplotplt 匯入。
  • 建立一個名為 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() 
編輯並執行程式碼