Record the time-domain plotting function.
It is convenient to draw directly with plt.plot(), but it lacks horizontal and vertical coordinate labels and horizontal and vertical coordinate scales. A function was written for this purpose, which is convenient for subsequent direct use.
plt.plot(arr)
plt.xlabel('t(s)')
plt.ylabel('Amp(mg)')
plt.show()
Define time-domain plotting functions
def plt_time_domain(arr, fs=1600, ylabel='Amp(mg)', title='原始数据时域图'):
"""
:fun: 绘制时域图模板
:param arr: 输入一维数组数据
:param fs: 采样频率
:param ylabel: y轴标签
:param title: 图标题
:return: None
"""
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # 显示中文
plt.rcParams['axes.unicode_minus'] = False # 显示负号
font = {
'family': 'Times New Roman', 'size': '20', 'color': '0.5', 'weight': 'bold'}
plt.figure(figsize=(8,3))
length = len(arr)
t = np.arange(0, length/fs, 1/fs)
plt.plot(t, arr)
plt.xlabel('t(s)')
plt.ylabel(ylabel)
plt.title(title)
#===保存图片====#
if img_save_path:
plt.savefig(img_save_path, dpi=500, bbox_inches = 'tight')
plt.show()
plt_time_domain(arr)
Before adding bbox_inches = 'tight'
, the saved picture is incomplete. After
adding bbox_inches = 'tight'
, the saved picture is complete.