【发布时间】:2016-12-05 19:12:04
【问题描述】:
我一直在努力使情节更流畅,就像 here 一样,但我的 X 是与 linspace 不兼容的日期时间对象..
我将 Xs 转换为 matplotlib 日期:
Xnew = matplotlib.dates.date2num(X)
X_smooth = np.linspace(Xnew.min(), Xnew.max(), 10)
Y_smooth = spline(Xnew, Y, X_smooth)
然后我得到一个空的情节,因为我的 Y_smooth 是
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
不知为何。
我怎样才能做到这一点?
编辑
这是我打印变量时得到的结果,我没有发现任何异常:
X : [datetime.date(2016, 7, 31), datetime.date(2016, 7, 30), datetime.date(2016, 7, 29)]
X new: [ 736176. 736175. 736174.]
X new max: 736176.0
X new min: 736174.0
XSMOOTH [ 736174. 736174.22222222 736174.44444444 736174.66666667
736174.88888889 736175.11111111 736175.33333333 736175.55555556
736175.77777778 736176. ]
Y [711.74, 730.0, 698.0]
YSMOOTH [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
【问题讨论】:
-
我刚刚尝试了一个示例,您的方法对我有用。尝试调试每一行。
Xnew.min()和Xnew.max()的值是多少?发布更多细节。X、X_smooth、Xnew的值是多少。对于debugging in a IPython during execution try using%debug到add breakpoints 或者可能使用logging 在执行期间查看中间值。 -
我编辑了问题并添加了变量
-
从你的输出我推断你的问题是样条,而不是日期时间。你能改写你的问题吗?也许用一组较小的数字来尝试你的问题,比如 10 而不是 300,这将在 SO 中更容易显示并且更容易调试。还要仔细检查
np.splie文档 -
我对 10 做了同样的事情,但没有区别。文档很小,没有示例:docs.scipy.org/doc/scipy/reference/generated/…,那里没有什么可学的;(
-
我想你想要来自 scipy 的
interp1d。它可以做一些样条变体
标签: python datetime matplotlib scipy interpolation