Matplotlib.pyplot.psd() in Python Last Updated : 21 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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.csd() Function The csd() function in pyplot module of matplotlib library is used to plot the cross-spectral density. Syntax: matplotlib.pyplot.csd(x, y, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, noverlap=None, pad_to=None, sides=None, scale_by_freq=None, return_line=None, \*, data=None, \*\*kwargs) Parameters: This method accept the following parameters that are described below: x: This parameter is a sequence of data. Fs : This parameter is a scalar. Its default value is 2. window: This parameter take a data segment as an argument and return the windowed version of the segment. Its default value is window_hanning() sides: This parameter specifies which sides of the spectrum to return. This can have following values : 'default', 'onesided' and 'twosided'. pad_to : This parameter contains the integer value to which the data segment is padded. NFFT : This parameter contains the number of data points used in each block for the FFT. detrend : This parameter contains the function applied to each segment before fft-ing, designed to remove the mean or linear trend {'none', 'mean', 'linear'}. scale_by_freq : This parameter is allows for integration over the returned frequency values. noverlap : This parameter is the number of points of overlap between blocks. Fc : This parameter is the center frequency of x. return_line : This parameter include the line object plotted in the returned values. Returns: This returns the following: Pxx:This returns the values for the power spectrum P_{xx} before scaling. freqs :This returns the frequencies for the elements in Pxx. line :This returns the line created by this function. The resultant is (Pxx, freqs, line) Below examples illustrate the matplotlib.pyplot.psd() function in matplotlib.pyplot: Example #1: Python3 # Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt dt = 0.01 t = np.arange(0, 30, dt) nse1 = np.random.randn(len(t)) s1 = 1.5 * np.sin(2 * np.pi * 10 * t) + nse1 + np.cos(np.pi * t) plt.psd(s1**2, 512, 1./dt, color ="green") plt.xlabel('Frequency') plt.ylabel('PSD(db)') plt.suptitle('matplotlib.pyplot.psd() function \ Example', fontweight ="bold") plt.show() Output: Example #2: Python3 # Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt dt = 0.01 t = np.arange(0, 30, dt) nse1 = np.random.randn(len(t)) r = np.exp(-t / 0.05) cnse1 = np.convolve(nse1, r, mode ='same')*dt s1 = np.cos(np.pi * t) + cnse1 + np.sin(2 * np.pi * 10 * t) plt.psd(s1, 2**14, dt) plt.ylabel('PSD(db)') plt.xlabel('Frequency') plt.title('matplotlib.pyplot.psd() Example\n', fontsize = 14, fontweight ='bold') plt.show() Output: Comment More infoAdvertise with us Next Article Matplotlib.pyplot.sci() in Python S SHUBHAMSINGH10 Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads Matplotlib.pyplot.matshow() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002. matplotlib.pyplot.matshow() matplotli 2 min read Matplotlib.pyplot.sca() 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. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 1 min read Matplotlib.pyplot.sci() 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. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read Matplotlib.pyplot.gca() in Python Matplotlib is a library in Python and it is a numerical - mathematical extension for the NumPy library. Pyplot is a state-based interface to a Matplotlib module that provides a MATLAB-like interface.  matplotlib.pyplot.gca() Function The gca() function in pyplot module of matplotlib library is used 2 min read matplotlib.pyplot.pcolormesh() 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.pcolormesh() Function: The pcolormesh() function in pyplot module of matplotlib library 2 min read Matplotlib.pyplot.hsv() 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.hsv() Function The hsv() function in pyplot module of matplotlib library is used to set 2 min read Like