Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down