diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 8745be6ad6a77..07d60db783d6d 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -160,6 +160,7 @@ def test_autocorrelation_plot(self): def test_lag_plot(self): from pandas.tools.plotting import lag_plot _check_plot_works(lag_plot, self.ts) + _check_plot_works(lag_plot, self.ts, lag=5) @slow def test_bootstrap_plot(self): diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 165ad73ee1312..042ab3418be60 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -520,12 +520,13 @@ def random_color(column): return ax -def lag_plot(series, ax=None, **kwds): +def lag_plot(series, lag=1, ax=None, **kwds): """Lag plot for time series. Parameters: ----------- series: Time series + lag: lag of the scatter plot, default 1 ax: Matplotlib axis object, optional kwds: Matplotlib scatter method keyword arguments, optional @@ -535,12 +536,12 @@ def lag_plot(series, ax=None, **kwds): """ import matplotlib.pyplot as plt data = series.values - y1 = data[:-1] - y2 = data[1:] + y1 = data[:-lag] + y2 = data[lag:] if ax is None: ax = plt.gca() ax.set_xlabel("y(t)") - ax.set_ylabel("y(t + 1)") + ax.set_ylabel("y(t + %s)" % lag) ax.scatter(y1, y2, **kwds) return ax