2017-02-23 73 views
0

我需要做的是讀取文件的時間,xy職位。 時間以小時爲單位,但是我希望以秒爲間隔生成xy的位置。使用插值函數

我對此很困惑,因爲不知道我是否把它當作1D等。 編輯,關於時間和位置的函數是未知的,但是有一種趨勢。

+0

你的內插是1D(僅一次),因此使用[interp1d](https://docs.scipy.org/doc/scipy/reference/generated/scipy .interpolate.interp1d.html)使用次數作爲第一個參數並將x _and_ y組合爲單個數組作爲第二個參數 –

回答

0

所有你需要做的是在單位時間確定,當你做插值,確保公正細分每個間隔爲3600(因爲有3600秒一小時。

我創建了一個例子假設指數和正弦趨勢在x和y。

import numpy as np 
import matplotlib.pyplot as plt 
from scipy import interpolate 
mytime = np.arange(0, 10) 
x = np.sin(mytime) 
y = np.exp(-mytime/3.0) 
f = interpolate.interp1d(mytime, x, kind = 'cubic') 
g = interpolate.interp1d(mytime, y, kind = 'cubic') 
mytimenew = np.arange(0, 9, 1/3600) 
xnew = f(mytimenew) 
ynew = g(mytimenew) 
plt.plot(mytime, x, 'o', mytimenew, xnew, '-') 
plt.plot(mytime, y, 'o', mytimenew, ynew, '-') 
plt.show() 
+0

唯一的問題是我不知道x和y的趨勢,? – point0zero