Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH Added Seasonal-Diagnostic Plot to graphics.tsaplots#9519

Open
jalopezp wants to merge 7 commits intostatsmodels:mainfrom
jalopezp:seasonaldiagnosticplot
Open

ENH Added Seasonal-Diagnostic Plot to graphics.tsaplots#9519
jalopezp wants to merge 7 commits intostatsmodels:mainfrom
jalopezp:seasonaldiagnosticplot

Conversation

@jalopezp
Copy link

STL requires a parameter called seasonal to be set. The authors of the technique recommend a plot called the Seasonal-Diagnostic Plot to visualise how the seasonal parameter is affecting the seasonal components. I added this plot to graphics.tsaplots and a notebook to explain how to use it.

Copy link
Member

@bashtage bashtage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes to improve the performance and interpretation. Also need to add a test that will run through the various configurations of optional arguments to make sure there aren't any issues. Test is only really for smoke as we dont' verify the figure.

period_length : int
The length of the period. Should match the `period` parameter used to
decompose the series.
select : int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really get much from select, or its description. Is this the base name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing this with the co2 dataset where the periodicity is 52. 52 subplots is too many so I added this parameter to specify how many to subcycles to select and plot. A disadvantage here was that the subplots were selected for you, so you couldn't ask it to display the first 13 weeks, then the next 13 weeks and so on. But I've added the option to select which subcycles specifically to plot by passing in a list. Called the parameter subplots, hope it's better.

Returns an matplotlib object of type Figure with the
Seasonal-Diagnostic Plot.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add an

Example
-------

section. Ideally one that will generate an actual plot which can then appear in the web docs.

fig, axs = mpl.pyplot.subplots(sharex=True, sharey=True,
squeeze=False, nrows=nrows, **kwargs)

p_to_plot = [math.floor(i*period_length / select) for i in range(select)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use np.floor and vector ops. We almost exclusively avoid math.

Something like

np.floor(np.arange(select) * period_length / select))


p_to_plot = [math.floor(i*period_length / select) for i in range(select)]
if subseries_labels is None:
subseries_labels = [f'Cycle-subseries {i + 1}' for i in period_length]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not none you should check that there are enough and error if not.


for ax, k in zip(fig.get_axes(), p_to_plot):
ax = seasonplot(x, k, period_length, ax=ax)
ax.set_title(subseries_labels[k])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to throw a str(...) around the labels in case of user ones

@jalopezp jalopezp requested a review from bashtage March 1, 2025 03:27
@bashtage
Copy link
Member

Would be nice to get this in. Could you clean the notebook? We only store unrendered notebooks.

@bashtage bashtage closed this Aug 19, 2025
@bashtage bashtage reopened this Aug 19, 2025
@bashtage
Copy link
Member

Closed and reopen to get new CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants