- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot signal in Matplotlib in Python?
To get the signal plot, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Get random seed value.
- Initialize dt for sampling interval and find the sampling frequency.
- Create random data points for t.
- To generate noise, get nse, r, cnse and s using numpy.
- Create a figure and a set of subplots using subplots() method.
- Set the title of the plot.
- Plot t and s data points.
- Set x and y labels.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True np.random.seed(0) dt = 0.01 # sampling interval Fs = 1 / dt # sampling frequency t = np.arange(0, 10, dt) # generate noise: nse = np.random.randn(len(t)) r = np.exp(-t / 0.05) cnse = np.convolve(nse, r) * dt cnse = cnse[:len(t)] s = 0.1 * np.sin(4 * np.pi * t) + cnse fig, axs = plt.subplots() axs.set_title("Signal") axs.plot(t, s, color='C0') axs.set_xlabel("Time") axs.set_ylabel("Amplitude") plt.show()
Output
- Related Articles
- How to a plot stem plot in Matplotlib Python?
- How to plot cdf in Matplotlib in Python?
- How to plot MFCC in Python using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to plot magnitude spectrum in Matplotlib in Python?
- How to plot an array in Python using Matplotlib?
- How to plot a density map in Python Matplotlib?
- How to plot a multivariate function in Python Matplotlib?
- How to plot a layered image in Matplotlib in Python?
- How to plot a phase spectrum in Matplotlib in Python?
- Matplotlib – How to plot the FFT of signal with correct frequencies on the X-axis?
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to plot longitudinal magnitude spectrum in Matplotlib using Python?
- How to plot an angle spectrum using Matplotlib in Python?
- How To Annotate Bars in Bar Plot with Matplotlib in Python?

Advertisements