源码
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
rate_h,hstrain=wavfile.read(r"D:/back-up/Ln/Python数据分析与展示/210405/H1_Strain.wav","rb")
rate_l,lstrain=wavfile.read(r"D:/back-up/Ln/Python数据分析与展示/210405/L1_Strain.wav","rb")
reftime,ref_H1 =np.genfromtxt(‘D:/back-up/Ln/Python数据分析与展示/210405/grawave.txt‘).transpose()
"""
读入文件,当文件名里面出现反斜杠等转义字符时,字符串前面加上一个r可以表示原始的字符串
使用read函数读取,然后我们还要获取一组数据,它是探测引力波机构提供的理论模型,读取的reftime是时间序列
genfromtxt执行两个循环,第一个循环将文件的每一行转换为字符串序列,第二个循环将字符串序列转换为相应数据类型
transpose将其转置
"""
htime_interval = 1/rate_h
litme_interval = 1/rate_l
htime_len = hstrain.shape[0]/rate_h#读取数据点的个数
htime = np.arange(-htime_len/2, htime_len/2, htime_interval)#取得时间序列
ltime_len = lstrain.shape[0]/rate_l
ltime = np.arange(-ltime_len/2, ltime_len/2, litme_interval)
fig = plt.figure(figsize=(12, 6))#创建大小12*6的绘图空间
plth = fig.add_subplot(221)
plth.plot(htime, hstrain, ‘y‘)#横坐标与纵坐标取值序列,y表示黄颜色
plth.set_xlabel(‘Time(seconds)‘)
plth.set_ylabel(‘H1 Strain‘)
plth.set_title(‘H1 Strain‘)
pltl = fig.add_subplot(222)
pltl.plot(ltime, lstrain, ‘g‘)#横坐标与纵坐标取值序列,g表示绿颜色
pltl.set_xlabel(‘Time (seconds)‘)
pltl.set_ylabel(‘L1 Strain‘)
pltl.set_title(‘L1 Strain‘)
pltref = fig.add_subplot(212)
pltref.plot(reftime, ref_H1)
pltref.set_xlabel(‘Time (seconds)‘)
pltref.set_ylabel(‘Timplate Strain‘)
pltref.set_title(‘Template‘)
fig.tight_layout()
plt.savefig("Gravitational_Waves_Original.png")
plt.show()
plt.close(fig)
原文:https://www.cnblogs.com/kwq717/p/14619198.html