##画图
figure_save = './figures/Falls_figures/'+dev_num+'/'+sensor_name
title = dev_num+sensor_name+'_频谱瀑布图_'+str(start_time)+'_'+str(end_time)
#图已经存在则不画
if os.path.exists(figure_save):
#已经存在的文件列表
files_list = os.listdir(figure_save)
file_name = title+'.png'
if file_name in files_list:
# print(file_name+'已经存在')
continue
fig = plt.figure(figsize=(20,10))
ax = plt.axes(projection='3d')
valid = False
for txt_name in sensor_txt_name_list:
try:
# print(txt_name) #******.txt
Fs = int(txt_name.split('_')[4])
# print('Fs:',Fs) #25600
filePath = dev_wave_path+"\\"+txt_name
df = read_txt(filePath)
if not df.empty:
# print(df.head())
df_fft_raw = FFT(Fs,df.loc[:,'accSpeed'])
ax.plot3D( df_fft_raw.loc[:,'Fre'], df_fft_raw.loc[:,'Amp'],'b') #3D折线图
valid = True
# break#时间段内的单个文件
except Exception as e:
print(txt_name,'画瀑布图失败')
continue
ax.set_zlabel('时间',fontsize=fontsize_1)
ax.set_ylabel('主频率幅值',fontsize=fontsize_1,labelpad=20)
ax.set_xlabel('频率',fontsize=fontsize_1+2,labelpad=10)
plt.title(title, fontsize=15, pad=50)
ax.view_init(-38,87)#-38,87 #视角调整,一般是(-45,45)
if valid:
# plt.show()
if not os.path.exists(figure_save):
os.makedirs(figure_save)
file = figure_save+"/"+title+'.png'
plt.savefig(file)
plt.close()