How to create multiple subplots for plots made for Fourier analysis decomposition

Viewed 12

So, I want to show three plots which are made using sm.tsa.seasonal_decompose(df) function and I want to show them three in line. Here is a code:

import statsmodels.api as sm
res_cpi = sm.tsa.seasonal_decompose(data['cpi'])
resplot_cpi = res_cpi.plot()
res_stock = sm.tsa.seasonal_decompose(data['stock_exchange'])
resplot_stock = res_stock.plot()
res_supply = sm.tsa.seasonal_decompose(data['money_supply'])
resplot_supply = res_supply.plot()

And then I use plt.subplots()

fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
res_cpi.plot()
res_stock.plot()
res_supply.plot()

But it does't put these three plot in one level. I know I should use "ax1", "ax2" and "ax3" but it results in following error:

AttributeError: 'AxesSubplot' object has no attribute 'resplot_cpi'

So my last thought was to write below code:

fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
ax1.plot(res_cpi)

But I gets this error:

TypeError: float() argument must be a string or a number, not 'DecomposeResult'

I use this model to perform Fourier docompose -> https://towardsdatascience.com/fourier-transform-for-time-series-292eb887b101

0 Answers
Related