import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
import csv
from scipy import signal#去线性趋势主要用的库
import numpy as np
data = []
data1 = []
data2 = []
data3 = []
# with open('D:\keyan_z\lvbo_output\lvbo.csv','r') as csvfile:
with open('C://Users//Lenovo//Desktop//999.csv', 'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
data.append(float(row[0]))
data1.append(float(row[1]))#原数据
data2.append(float(row[2]))#原数据
data3.append(float(row[3]))#原数据
# print(numpy.array(data))
a_detrend=signal.detrend(data1, axis=0, type='linear')#去线性趋势后的数据
b_detrend=signal.detrend(data2, axis=0, type='linear')#去线性趋势后的数据
c_detrend=signal.detrend(data3, axis=0, type='linear')#去线性趋势后的数据
# plt.plot(data1, color='lightcoral')
# plt.plot(a_detrend+np.array(data1).mean())
plt.plot(data2, color='orange')
plt.plot(b_detrend)#只对比
# plt.plot(data3, color='cornflowerblue')
# plt.title('model loss and acc')
plt.ylabel('gait')
plt.xlabel('Time(0.01s)')
plt.legend(['raw-data', 'detrend'],loc='upper right')
plt.show()
# # print(data2)
# plt.subplot(4, 1, 1)
# plt.plot(data)
# plt.ylabel('raw')
# # plt.xlabel('Time(0.01s)')
# # x_major_locator = MultipleLocator(10)
# # y_major_locator = MultipleLocator(0.2)# 把y轴的刻度间隔设置为0.1,并存在变量里
# # ax = plt.gca()# ax为两条坐标轴的实例
# # ax.xaxis.set_major_locator(x_major_locator)
# # ax.yaxis.set_major_locator(y_major_locator)# 把y轴的主刻度设置为0.1的倍数
# # plt.xlim(1, 100)
# # plt.ylim(0.8, 1.4)# 把y轴的刻度范围设置为-5到110,同理,-5不会标出来,但是能看到一点空白
#
# plt.subplot(4, 1, 2)
# plt.plot(data1)
# plt.ylabel('butterwolth')
#
# plt.subplot(4, 1, 3)
# plt.plot(data2)
# plt.ylabel('sliding')
#
# plt.subplot(4, 1, 4)
# plt.plot(data3)
# plt.ylabel('low')
# plt.xlabel('Sample point')
#
#
# # plt.legend()
# plt.show()
#
#
#
#
|