在python中对齐三个时间序列

use*_*898 4 python time-series pandas

我有以下时间序列: 在此处输入图片说明

我只想在时间= 800之后根据最小点对齐来对齐信号。

我尝试了以下方法来对齐熊猫中的两个信号:

from pandas import *
import pandas as pd
s1 = Series(vec1)
s2 = Series(vec2)
s3 = s1.align(s2,join='inner')

s1 = np.array(s1)
s2 = np.array(s2)
s3 = np.array(s3)

plt.plot(t,s1)
plt.plot(t,s2)
plt.plot(t,s3)
plt.show()
Run Code Online (Sandbox Code Playgroud)

完全按照原始形式显示对齐的信号。关于如何实现最小对齐的任何建议?

cph*_*wis 5

查找并对齐最小值:

import matplotlib.pyplot as plt  #making toy data
x = np.arange(0, 2, .05)

s = []
s.append(np.sin(x*3))
s.append(np.cos(x*4+0.3))
s.append(np.sin(x)*np.exp(2-x)*-1)
plt.clf()
plt.plot(x, s[0], x, s[1], x, s[2])
plt.show()
plt.clf()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

mindexes = map(lambda x: x.argmin(), s)  #finding the minima
shifts = mindexes - min(mindexes)

def shifted(shift, x, s):
    if shift == 0:   #x[:-0] was not what I wanted.
        return x, s
    else:
        return x[:-1*shift], s[shift:]

for i in (0,1,2):
    px, py = shifted(shifts[i], x, s[i]) 
    plt.plot(px, py)
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明