【发布时间】:2018-05-04 09:18:36
【问题描述】:
我正在用 Python 编写一个应用程序,它收集有关温度和时间的信息并将它们绘制在图表中。
在这里看到Smooth line with spline + datetime objects doesn't work
我想插入几个温度值以使图形温度时间更平滑。
此函数检索温度和时间的值,并将它们放入与位置(卧室和厨房)相关的数组中:
xTemp, yTemp = dataList[1].split(',')
xTime, yTime = dataList[3].split(',')
t = datetime.fromtimestamp(float(xTime)).strftime('%Y-%m-%d %H:%M:%S') # get time string
st = datetime.strptime(t, '%Y-%m-%d %H:%M:%S') # get datetime from time string
x.append(st)
y.append(xTemp)
X = np.array(x)
Y = np.array(y)
Xnew = matplotlib.dates.date2num(X)
if(len(X) >= 5):
X_smooth = np.linspace(Xnew.min(), Xnew.max(), 10)
Y_smooth = interp1d(X, Y, X_smooth)
# , assume_sorted = True, kind = 'quadratic')
a.plot(X_smooth, Y_smooth)
我遇到了这个错误:
NotImplementedError: [736817.73790509 736817.73791152 736817.73791795 736817.73792438
736817.73793081 736817.73793724 736817.73794367 736817.7379501
736817.73795653 736817.73796296] is unsupported: Use fitpack routines for other types.
你能帮帮我吗?谢谢
【问题讨论】:
-
哪一行会抛出这个错误?我建议提供尽可能短但可运行的代码。看来,您的代码处于循环中(是吗?)
-
interp1d的插值
-
在这种情况下,请获取
X、Y和X_smooth(使用调试器或仅打印它们)并将上面的代码替换为这些值。 -
@betonalpfa 是的,我的代码在一个 for 循环中,它从 json 文件中检索 ip 和端口,并执行一个请求 witch CoAP 协议(实际上是套接字),这样我就可以动态更新每秒或更少的图表
标签: python datetime tkinter spline