Seasonal_Decompose gives plot filled to the brim with blue lines

66 views Asked by At

When i'm plotting the seasonal_decompose I get a plot filled to the brim with blue lines, the whole plot is filled. What is going wrong?seasonal decompose

decomposition = sm.tsa.seasonal_decompose(df1['Column1'], period=12)


plt.figure(figsize=(12, 8))
plt.subplot(4, 1, 1)
plt.plot(df1['Column1'], label='Original')
plt.legend()


plt.subplot(4, 1, 2)
plt.plot(decomposition.trend, label='Trend')
plt.legend()


plt.subplot(4, 1, 3)
plt.plot(decomposition.seasonal, label='Season')
plt.legend()

plt.subplot(4, 1, 4)
plt.plot(decomposition.resid, label='Residual')
plt.legend()

plt.tight_layout()
plt.show()

I've tried using different type of decompose ("Multiplicative" or "Additive")

1

There are 1 answers

2
jlandercy On

Here is a MCVE for seasonal decomposition:

import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.seasonal import seasonal_decompose

df = pd.read_csv("https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_trend_gl.csv", header=24)
df['timestamp'] = pd.to_datetime(dict(year=df.year, month=df.month, day=df.day))
df = df.set_index("timestamp")

decomposition = seasonal_decompose(df["smoothed"], period=365)

fig, axes = plt.subplots(4, 1, sharex=True)
df.smoothed.plot(ax=axes[0])
decomposition.trend.plot(ax=axes[1])
decomposition.seasonal.plot(ax=axes[2])
decomposition.resid.plot(ax=axes[3])

enter image description here