Autocorrelation plot using Matplotlib Last Updated : 06 Aug, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Autocorrelation plots are a commonly used tool for checking randomness in a data set. This randomness is ascertained by computing autocorrelations for data values at varying time lags. Characteristics Of Autocorrelation Plot : It measures a set of current values against a set of past values and finds whether they correlate.It is the correlation of one-time series data to another time series data which has a time lag.It varies from +1 to -1.An autocorrelation of +1 indicates that if time series one increases in value the time series 2 also increases in proportion to the change in time series 1.An autocorrelation of -1 indicates that if time series one increases in value the time series 2 decreases in proportion to the change in time series 1. Application of Autocorrelation: Pattern recognition.Signal detection.Signal processing.Estimating pitch.Technical analysis of stocks.Plotting the Autocorrelation Plot To plot the Autocorrelation Plot we can use matplotlib and plot it easily by using matplotlib.pyplot.acorr() function. Syntax: matplotlib.pyplot.acorr(x, *, data=None, **kwargs)Parameters: 'x' : This parameter is a sequence of scalar.'detrend' : This parameter is an optional parameter. Its default value is mlab.detrend_none.'normed' : This parameter is also an optional parameter and contains the bool value. Its default value is True.'usevlines' : This parameter is also an optional parameter and contains the bool value. Its default value is True.'maxlags' : This parameter is also an optional parameter and contains the integer value. Its default value is 10.'linestyle' : This parameter is also an optional parameter and used for plotting the data points, only when usevlines is False.'marker' : This parameter is also an optional parameter and contains the string. Its default value is ‘o’. Returns: (lags, c, line, b) Where: lags are a length 2`maxlags+1 lag vector.c is the 2`maxlags+1 auto correlation vector.line is a Line2D instance returned by plot.b is the x-axis. Example 1: Python3 # Importing the libraries. import matplotlib.pyplot as plt import numpy as np # Data for which we plot Autocorrelation. data = np.array([12.0, 24.0, 7., 20.0, 7.0, 22.0, 18.0,22.0, 6.0, 7.0, 20.0, 13.0, 8.0, 5.0, 8]) # Adding plot title. plt.title("Autocorrelation Plot") # Providing x-axis name. plt.xlabel("Lags") # Plotting the Autocorrelation plot. plt.acorr(data, maxlags = 10) # Displaying the plot. print("The Autocorrelation plot for the data is:") plt.grid(True) plt.show() Output: Example 2: Python3 # Importing the libraries. import matplotlib.pyplot as plt import numpy as np # Setting up the rondom seed for # fixing the random state. np.random.seed(42) # Creating some random data. data = np.random.randn(25) # Adding plot title. plt.title("Autocorrelation Plot") # Providing x-axis name. plt.xlabel("Lags") # Plotting the Autocorrelation plot. plt.acorr(data, maxlags = 20) # Displaying the plot. print("The Autocorrelation plot for the data is:") plt.grid(True) plt.show() Output: Comment More infoAdvertise with us Next Article Matplotlib.pyplot.acorr() in Python V VishwashVishwakarma Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads Plotting Correlation Matrix using Python Correlation means an association, It is a measure of the extent to which two variables are related. 1. Positive Correlation: When two variables increase together and decrease together. They are positively correlated. '1' is a perfect positive correlation. For example - demand and profit are positiv 3 min read Matplotlib.pyplot.acorr() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.acorr() Function The acorr() function in pyplot module of matplotlib library is used to 2 min read Python Pandas - Plotting the Autocorrelation Plot 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. Autocorrelation plot Autocorrelation plots are a 2 min read Dynamically Updating Plot In Matplotlib This article shows how to dynamically update a Matplotlib (a data visualization library for Python programming language) plot as the data changes. It provides two methods to plot - first the API (useful for large programs and/or ones requiring deep control) and second the Pyplot interface (inspired 5 min read Matplotlib.pyplot.connect() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.connect() Function This method is used to connect an event with string s to a function. 3 min read Create Scatter Charts in Matplotlib using Flask In this article, we will see how to create charts in Matplotlib with Flask. We will discuss two different ways how we can create Matplotlib charts in Flask and present it on an HTML webpage with or without saving the plot using Python. File structure  Create and Save the Plot in the Static Directory 4 min read Like