如何在Python的Matplotlib中绘制信号图形? 要获得信号绘图,可以按照以下步骤进行- 设置图形大小并调整子图之间及周围的填充。 获得随机种子值。 为采样间隔初始化 dt 并找到采样频率。 为 t 创建随机数据点。 为了产生噪声, 使用numpy获取nse、r、cnse和s。 使用 subplots() 方法创建一个图形和一组子图。 设置绘图的标题。 绘制 t 和 s 数据点。 设置 x 和 y 标签。 使用 show() 方法显示图形。 示例 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 # 采样间隔 Fs = 1 / dt # 采样频率 t = np.arange(0, 10, dt) # 生成噪声: 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() PythonCopy 输出