What is matplotlib.pyplot.acorr() funtion in Python?
Digital Image Processing is a significant aspect of data science. It is used in image modification and enhancement to acquire image attributes that lead to a greater understanding of data.
matplotlib is a Python library that provides a multitude of functions to visualize and plot data. The matplotlib.pyplot.acorr() function is used to plot the autocorrelation of data and is used mainly in data analysis.
Syntax
matplotlib.pyplot.acorr(x, *, data=None, **kwargs)
Parameters
-
x: A sequence of scalars. This parameter is required. -
detrend: A callable function that detrendsx. The default ismlab.detrend_none. (Optional) -
normed: A Boolean value that, if set toTrue, normalizesxto unit length. The default isTrue. (Optional) -
usevlines: A Boolean value that, if set toTrue, plots vertical lines from0to the acorr values. The default isTrue. (Optional) -
maxlags: An integer value that specifies the number of lags to show. The default is10. (Optional) -
linestyle: ALine2Dobject that specifies the line style for plotting points. Used only whenusevlinesisFalse. (Optional) -
marker: A string value that specifies the marker for plotting points. Used only whenusevlinesisFalse. (Optional)
Return value
The method returns a tuple (lags, c, line, b). lags is the lag vector, c is the correlation vector, line is a LineCollection object if usevlines is True, and b is the horizontal line at y=0 if usevlines is True.
Code example
#import librariesimport matplotlib.pyplot as pltimport numpy as np#initialize datax = np.array([14.8, 61.7, 4.3, 17.2, 53.7, 19.0, 24.3, 13.7])#plot correlationplt.acorr(x,normed = True,maxlags = 5)#add labelsplt.xlabel('X-axis')plt.ylabel('Y-axis')#show the autocorrelation plotplt.show()
The code plots an autocorrelation for the specified data as seen below.