Eastsun
Eastsun

Reputation: 18859

Is there any method in python like `lag.plot1` in r?

I want to find a method in seaborn or statsmodels with the ability produce scatterplot matrices as lag.plot1 in r. I could implement a simple version as following:

In [74]: def lag_plot1(x, nrow, ncol):
    ...:     import matplotlib.pyplot as plt
    ...:     fig, axs = plt.subplots(nrow, ncol, figsize=(3*ncol, 3*nrow))
    ...:     for row in range(nrow):
    ...:         for col in range(ncol):
    ...:             offset = row*ncol + col + 1
    ...:             axs[row][col].scatter(x[offset:], x[:-offset], marker='o')
    ...:             axs[row][col].set_ylabel('x(t)')
    ...:             axs[row][col].set_title('x(t-%d)' % offset)
    ...:     return fig
    ...: 

In [75]: lag_plot1(recur, 4, 3)

enter image description here

Upvotes: 1

Views: 193

Answers (1)

Josef
Josef

Reputation: 22897

There is a lag_plot in pandas http://pandas.pydata.org/pandas-docs/stable/visualization.html#lag-plot but it doesn't plot the grid of plots for different lags, AFAICS.

statsmodels doesn't have a lag_plot, but there are still open issues to add more plots to support model diagnostics.

Upvotes: 1

Related Questions