Skip to content

Commit 37bb53e

Browse files
committed
ENH: commit autocorrelation_plot stuff by hand #1425
1 parent bbada0c commit 37bb53e

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

doc/source/visualization.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,31 @@ implies that the underlying data are not random.
297297
298298
plt.figure()
299299
300-
data = Series(0.1 * np.random.random(1000) +
300+
data = Series(0.1 * np.random.random(1000) +
301301
0.9 * np.sin(np.linspace(-99 * np.pi, 99 * np.pi, num=1000)))
302302
303303
@savefig lag_plot.png width=6in
304-
lag_plot(data)
304+
lag_plot(data)
305+
306+
Autocorrelation Plot
307+
~~~~~~~~~~~~~~~~~~~~
308+
309+
Autocorrelation plots are often used for checking randomness in time series.
310+
This is done by computing autocorrelations for data values at varying time lags.
311+
If time series is random, such autocorrelations should be near zero for any and
312+
all time-lag separations. If time series is non-random then one or more of the
313+
autocorrelations will be significantly non-zero. The horizontal lines displayed
314+
in the plot correspond to 95% and 99% confidence bands. The dashed line is 99%
315+
confidence band.
316+
317+
.. ipython:: python
318+
319+
from pandas.tools.plotting import autocorrelation_plot
320+
321+
plt.figure()
322+
323+
data = Series(0.7 * np.random.random(1000) +
324+
0.3 * np.sin(np.linspace(-9 * np.pi, 9 * np.pi, num=1000)))
325+
326+
@savefig autocorrelation_plot.png width=6in
327+
autocorrelation_plot(data)

pandas/tests/test_graphics.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ def test_kde(self):
7575
ax = self.ts.plot(kind='kde', logy=True)
7676
self.assert_(ax.get_yscale() == 'log')
7777

78+
@slow
79+
def test_autocorrelation_plot(self):
80+
from pandas.tools.plotting import autocorrelation_plot
81+
_check_plot_works(autocorrelation_plot, self.ts)
82+
_check_plot_works(autocorrelation_plot, self.ts.values)
83+
7884
@slow
7985
def test_lag_plot(self):
8086
from pandas.tools.plotting import lag_plot

pandas/tools/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def autocorrelation_plot(series, ax=None):
216216
"""
217217
import matplotlib.pyplot as plt
218218
n = len(series)
219-
data = series.values
219+
data = np.asarray(series)
220220
if ax == None:
221221
ax = plt.gca(xlim=(1, n), ylim=(-1.0, 1.0))
222222
mean = np.mean(data)

0 commit comments

Comments
 (0)