Matplotlib.pyplot.specgram() in Python Last Updated : 21 Apr, 2020 Comments Improve Suggest changes 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.specgram() Function The specgram() function in pyplot module of matplotlib library is used to plot a spectrogram. Syntax: matplotlib.pyplot.specgram(x, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, noverlap=None, cmap=None, xextent=None, pad_to=None, sides=None, scale_by_freq=None, mode=None, scale=None, vmin=None, vmax=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. Fc: This parameter is also contains the integer value to offsets the x extents of the plot to reflect the frequency range. Its default value is 0 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. mode : This parameter is that what sort of spectrum to use {‘default’, ‘psd’, ‘magnitude’, ‘angle’, ‘phase’}. noverlap : This parameter is the number of points of overlap between blocks. scale : This parameter contains the scaling of the values in the spec {‘default’, ‘linear’, ‘dB’}. Fc : This parameter is the center frequency of x. camp: This parameter is a matplotlib.colors.Colormap instance. Returns: This returns the following: spectrum :This returns the angle spectrum in radians. freqs :This returns the frequencies corresponding to the elements in spectrum. t: This returns the times corresponding to midpoints of segments. im: This returns the image created by imshow containing the spectrogram. The resultant is (spectrum, freqs, t, im) Below examples illustrate the matplotlib.pyplot.specgram() function in matplotlib.pyplot: Example 1: Python3 1== # Implementation of matplotlib function import matplotlib.pyplot as plt import numpy as np dt = 0.005 t = np.arange(0.0, 20.0, dt) x = np.sin(np.pi * t) + 1.5 * np.cos(np.pi * 2*t) plt.specgram(x, Fs = 1) plt.title('matplotlib.pyplot.specgram() Example\n', fontsize = 14, fontweight ='bold') plt.show() Output: Example 2: Python3 1== # Implementation of matplotlib function import matplotlib.pyplot as plt import numpy as np np.random.seed(9360801) dt = 0.0005 t = np.arange(0.0, 20.0, dt) s1 = np.sin(4 * np.pi * 100 * t) s2 = 1.5 * np.sin(1.5 * np.pi * 400 * t) s2[t <= 10] = s2[12 <= t] = 0 nse = 0.2 * np.random.random(size = len(t)) x = s1 + s2 + nse NFFT = 512 Fs = int(1.0 / dt) plt.specgram(x, Fs = Fs, cmap = plt.cm.bone) plt.title('matplotlib.pyplot.specgram() Example\n', fontsize = 14, fontweight ='bold') plt.show() Output: Comment More infoAdvertise with us Next Article Matplotlib.pyplot.specgram() in Python S SHUBHAMSINGH10 Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads 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.angle_spectrum() 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 angle_spectrum() function in pyplot module of matplotlib library 2 min read Matplotlib.pyplot.savefig() in Python savefig() function in Python is used to save a plot created with Matplotlib to a file. It supports various formats like PNG, PDF, SVG, and more. This method allows you to specify additional parameters like file name, resolution, layout, and transparency, giving you control over the appearance and qu 3 min read Matplotlib.pyplot.show() 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. Sample Code - Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 2 min read Matplotlib.pyplot.xlim() 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.tripcolor() 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. Sample Code Python3 1== # sample code import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [16, 4, 1, 8 4 min read Matplotlib.pyplot.ylim() 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.ylim() Function The ylim() function in pyplot module of matplotlib library is used to g 2 min read Matplotlib.pyplot.xkcd() in Python One of the main process in Data Science is Data Visualization. Data Visualization refers to present a dataset in the form of graphs and pictures. We can identify upcoming trend by observing these Graphs. Python provides us with an amazing Data Visualization library in it which is Matplotlib which wa 2 min read Matplotlib.pyplot.yticks() 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.yticks() Function The annotate() function in pyplot module of matplotlib library is use 2 min read Like