Python去线性化趋势
生活随笔
收集整理的這篇文章主要介紹了
Python去线性化趋势
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
import csv
from scipy import signal#去線性趨勢主要用的庫
import numpy as npdata = []
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]))#原數(shù)據(jù)data2.append(float(row[2]))#原數(shù)據(jù)data3.append(float(row[3]))#原數(shù)據(jù)
# print(numpy.array(data))
a_detrend=signal.detrend(data1, axis=0, type='linear')#去線性趨勢后的數(shù)據(jù)
b_detrend=signal.detrend(data2, axis=0, type='linear')#去線性趨勢后的數(shù)據(jù)
c_detrend=signal.detrend(data3, axis=0, type='linear')#去線性趨勢后的數(shù)據(jù)
# plt.plot(data1, color='lightcoral')
# plt.plot(a_detrend+np.array(data1).mean())plt.plot(data2, color='orange')
plt.plot(b_detrend)#只對(duì)比
# 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軸的刻度間隔設(shè)置為0.1,并存在變量里
# # ax = plt.gca()# ax為兩條坐標(biāo)軸的實(shí)例
# # ax.xaxis.set_major_locator(x_major_locator)
# # ax.yaxis.set_major_locator(y_major_locator)# 把y軸的主刻度設(shè)置為0.1的倍數(shù)
# # plt.xlim(1, 100)
# # plt.ylim(0.8, 1.4)# 把y軸的刻度范圍設(shè)置為-5到110,同理,-5不會(huì)標(biāo)出來,但是能看到一點(diǎn)空白
#
# 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()
#
#
#
#
總結(jié)
以上是生活随笔為你收集整理的Python去线性化趋势的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Pytest前后置处理
- 下一篇: 在word中给公式添加序号