0

I am going to create an Arima model for time series data with the following DF of 157 rows:

enter image description here

I am trying to establish which decomposition is best suited to my data and have produced a multiplicative and additive decomposition of the series. I have plotted the two decomposition residuals in different subplots using following code:

# produce a multiplicative and additive decomposition of the series 
a = seasonal_decompose(actuals, model='a', freq=52) 
m = seasonal_decompose(actuals, model='m', freq=52)

a_model = a.trend+a.seasonal 
m_model = m.trend*m.seasonal


#plot the two decomposition residuals in different subplots
plt.style.use('ggplot')
plt.rcParams['figure.figsize']=(14,6)
x = actuals.index
residual_m = m.resid
plt.subplot(2,1,1)
plt.title('Multiplicative decomposition residuals')
plt.plot(x, residual_m, 'b', linewidth=2)
residual_a = a.resid
plt.tick_params(
     labelbottom=False)
plt.subplot(2,1,2)
plt.title('Additive decomposition residuals')
plt.plot(x, residual_a, 'r', linewidth=2)
plt.xticks(rotation=60)
plt.show()

This produces the following charts: enter image description here

As you can see the xaxis overlaps. I have searched and found a number of resolutions to reduce number of x tick marks. Whether that's to tell matplotlib the desired number of ticks using 'ax.locator_params(nbins=10, axis='x')' (this gives AttributeError: 'numpy.ndarray' object has no attribute 'locator_params'). Or when I try 'fig.autofmt_xdate()' (no effect). I think these resolutions do not work as my xaxis is the index.

Can anyone help with the correct logic? Preferabaly I just want to reduce the amount of xaxis labels but it would also be really good to space it out by every 4 bins/weeks.

DSouthy
  • 169
  • 1
  • 3
  • 12
  • Your dates look like strings, not proper datetime types. Convert them with `pd.to_datetime`, which will allow the api to space them properly, and then format the plot labels with https://stackoverflow.com/q/14946371/7758804 – Trenton McKinney May 18 '21 at 18:33
  • **[Don't Post Screenshots](https://meta.stackoverflow.com/questions/303812/)**. It's likely the question will be down-voted and closed. You're discouraging assistance because no one wants to retype your data or code, and screenshots are often illegible. [edit] the question and **add text**. Please see [How to provide a reproducible copy of your DataFrame using `df.head(15).to_clipboard(sep=',')`](https://stackoverflow.com/questions/52413246). – Trenton McKinney May 18 '21 at 18:46

0 Answers0