Plotting cross-spectral density in Python using Matplotlib Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Matplotlib is a comprehensive library consisting of modules that are used for Data Visualization just like MATLAB. Pyplot is a further module which makes functions and methods executable. Plotting Cross-Spectral Density The cross-spectral density compares two signals, each from different source taking into account both amplitude and phase difference of the two signals. In Python, this function is carried out using the Pyplot module's method matplotlib.pyplot.csd()Syntax: matplotlib.pyplot.csd(x, y) Here, x and y are 1-D arrays or a sequence having the data.Let us take two signals and plot their CSD: Signal 1 has time period from 0 to 1 second and 0.1 radian phase angle with frequency being calculated using sin() function.Similarly, Signal 2 has time period from 5 to 10 seconds and 0.25 radians phase angle.Taking these two signals, we plot their cross spectral density. Example 1: Plotting Signal 1 python3 import numpy as np import matplotlib.pyplot as plt time = np.arange(0, 1, 0.1) amp = np.sin(time) plt.plot(time, amp) plt.title("Signal 1") plt.show() Output: Example 2: Plotting Signal 2 Python3 import numpy as np import matplotlib.pyplot as plt t = np.arange(5, 10, 0.25) ampl = np.sin(t) plt.plot(t, ampl) plt.title("Signal 2") plt.show() Output: Example 3: Plotting the cross-spectral density Python3 import numpy as np import matplotlib.pyplot as plt # Signal 1 time = np.arange(0, 1, 0.1) amp = np.sin(time) # Signal 2 t = np.arange(5, 10, 0.25) ampl = np.sin(t) # Cross-spectral density plt.csd(amp, ampl) plt.show() Output: Example 4: Using discrete lists or arrays Python3 import numpy as np import matplotlib.pyplot as plt a = np.arange(5) b = np.arange(10, 30) plt.csd(a, b) plt.show() Output: Comment More infoAdvertise with us Next Article Plotting cross-spectral density in Python using Matplotlib R riasehgal1999 Follow Improve Article Tags : Python Write From Home Python-matplotlib Practice Tags : python Similar Reads Plot the power spectral density using Matplotlib - Python matplotlib.pyplot.psd() function is used to plot power spectral density. In the Welch's average periodogram method for evaluating power spectral density (say, Pxx), the vector 'x' is divided equally into NFFT segments. Every segment is windowed by the function window and detrended by the function de 6 min read Plotting a Spectrogram using Python and Matplotlib Prerequisites: Matplotlib A spectrogram can be defined as the visual representation of frequencies against time which shows the signal strength at a particular time. In simple words, a spectrogram is nothing but a picture of sound. It is also called voiceprint or voice grams. A spectrogram is shown 3 min read Plotting Sine and Cosine Graph using Matplotlib in Python Data visualization and Plotting is an essential skill that allows us to spot trends in data and outliers. With the help of plots, we can easily discover and present useful information about the data. In this article, we are going to plot a sine and cosine graph using Matplotlib in Python. Matplotlib 3 min read Plotting Histogram in Python using Matplotlib Histograms are a fundamental tool in data visualization, providing a graphical representation of the distribution of data. They are particularly useful for exploring continuous data, such as numerical measurements or sensor readings. This article will guide you through the process of Plot Histogram 6 min read Plot the magnitude spectrum in Python using Matplotlib A Signal is an electromagnetic field or an electric current to transmit data. There are various components of a signal such as frequency, amplitude, wavelength, phase, angular frequency and period from which it is described. A periodic signal can be represented using the below sine function: y = A s 3 min read Like