首页 > 解决方案 > 使用 Pandas 自相关图 - 如何限制 x 轴以使其更具可读性?

问题描述

我正在使用python 3.7。

我正在使用 ARIMA 模型执行时间序列预测。我正在使用自相关图评估 ARIMA 数据的属性 - 特别是使用 pandas.plotting 中的 autocorrelation_plot。

我的数据有 50,000 条左右的记录,使得情节非常繁忙,很难找出任何具体的趋势。有没有办法限制 x 轴以使前几百个滞后更加清晰?

我不能分享实际的情节,但我的代码如下:

import pandas as pd
from pandas.plotting import autocorrelation_plot

#Import Data
time_series_2619 = pd.read_csv("Consumption/2619.csv", parse_dates=['Date/Time'], index_col = ['Date/Time'])['Recording']

#Auto Correlation Plot
autocorrelation_plot(time_series_2619)

我在文档中找不到任何内容。

标签: pythonpandastime-seriesautocorrelation

解决方案


autocorrelation_plot返回一个 matplotlib.axis 对象。因此,您可以简单地使用该set_xlim()方法来限制 x 轴:

ax = autocorrelation_plot(time_series_2619)
ax.set_xlim([0, 500])

推荐阅读