開始使用免費開始

繪製各個組成部分

你也可以從時間序列分解物件中擷取其他推斷出的量。以下程式碼示範如何擷取觀測值(observed)、趨勢(trend)與雜訊(或殘差,resid)組成部分。

observed = decomposition.observed
trend = decomposition.trend
residuals = decomposition.resid

接著,你可以使用這些已擷取的組成部分,分別繪圖。

你在上一個練習建立的 decomposition 物件已經在你的工作環境中可用。

本練習屬於課程

使用 Python 視覺化時間序列資料

檢視課程

練習說明

  • decomposition 物件中擷取 trend 組成部分。
  • 繪製這個趨勢組成部分。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Extract the trend component
trend = ____.____

# Plot the values of the trend
ax = ____.____(figsize=(12, 6), fontsize=6)

# Specify axis labels
ax.set_xlabel('Date', fontsize=10)
ax.set_title('Seasonal component the CO2 time-series', fontsize=10)
plt.show()
編輯並執行程式碼