Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Pandas Autocorrelation Plot - how to limit x-axis to make it more readable?

I am using python 3.7.

I am performing time series forecasting using an ARIMA model. I am assessing the properties of my data for ARIMA using an Autocorrelation Plot - specifically using autocorrelation_plot from pandas.plotting.

My data has 50,000 records or so, making the plot extremely busy and hard to pick out any specific trends. Is there a way to limit the x-axis to bring the first few hundred lags more into focus?

I can't share the actual plot, but my code is as follow:

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)

I couldn't find anything in the documentation.

like image 956
c_m_conlan Avatar asked Apr 11 '19 09:04

c_m_conlan


People also ask

What does autocorrelation plot tell us?

An autocorrelation plot is designed to show whether the elements of a time series are positively correlated, negatively correlated, or independent of each other. (The prefix auto means "self"— autocorrelation specifically refers to correlation among the elements of a time series.)

What is pandas autocorrelation?

Pandas can be used to plot the Autocorrelation Plot on a graph. Plotting the Autocorrelation Plot on a graph can be done using the autocorrelation_plot() method of the plotting module. This function generates the Autocorrelation plot for time series.

Can pandas be used for plotting?

Pandas uses the plot() method to create diagrams. We can use Pyplot, a submodule of the Matplotlib library to visualize the diagram on the screen. Read more about Matplotlib in our Matplotlib Tutorial.


2 Answers

autocorrelation_plot returns a matplotlib.axis object. Hence, you can simply use the set_xlim() method to limit the x-axis:

ax = autocorrelation_plot(time_series_2619)
ax.set_xlim([0, 500])
like image 192
mrzo Avatar answered Oct 16 '22 13:10

mrzo


Alternatively, you can use the plot_acf() function and specify the lags.

# import the plotting functions for act and pacf  
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
plot_acf(df1['Thousands of Passengers'], lags=40);
like image 32
Bryan Butler Avatar answered Oct 16 '22 12:10

Bryan Butler