Skip to content

Commit f25516a

Browse files
geierwesm
authored andcommitted
lag_plot() accepts variable lags
the default is still 1
1 parent d57c17c commit f25516a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandas/tests/test_graphics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def test_autocorrelation_plot(self):
160160
def test_lag_plot(self):
161161
from pandas.tools.plotting import lag_plot
162162
_check_plot_works(lag_plot, self.ts)
163+
_check_plot_works(lag_plot, self.ts, lag=5)
163164

164165
@slow
165166
def test_bootstrap_plot(self):

pandas/tools/plotting.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,13 @@ def random_color(column):
520520
return ax
521521

522522

523-
def lag_plot(series, ax=None, **kwds):
523+
def lag_plot(series, lag=1, ax=None, **kwds):
524524
"""Lag plot for time series.
525525
526526
Parameters:
527527
-----------
528528
series: Time series
529+
lag: lag of the scatter plot, default 1
529530
ax: Matplotlib axis object, optional
530531
kwds: Matplotlib scatter method keyword arguments, optional
531532
@@ -535,12 +536,12 @@ def lag_plot(series, ax=None, **kwds):
535536
"""
536537
import matplotlib.pyplot as plt
537538
data = series.values
538-
y1 = data[:-1]
539-
y2 = data[1:]
539+
y1 = data[:-lag]
540+
y2 = data[lag:]
540541
if ax is None:
541542
ax = plt.gca()
542543
ax.set_xlabel("y(t)")
543-
ax.set_ylabel("y(t + 1)")
544+
ax.set_ylabel("y(t + %s)" % lag)
544545
ax.scatter(y1, y2, **kwds)
545546
return ax
546547

0 commit comments

Comments
 (0)