#import packages
import heartpy as hp
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
sample_rate = 40
data = np.loadtxt('temp.1D')
#plt.figure(figsize=(12,4))
#plt.plot(data)
#plt.show()
wd, m = hp.process(data,40) #run analysis
#function called periodically from funcanimation
def animate(i):
y_values.append(next(index))
plt.cla()
#keep reading from open heart rate file
#visualise in plot of custom size
plt.figure(figsize=(12,4))
plot_object = hp.plotter(wd,m,moving_average=True)
#set up plot to call animate () function periodically
ani = animation.FuncAnimation(plot_object, animate, interval=1000)
plt.show()
暂时收到错误:
File "/Users/jsmith/Documents/hearttest.py", line 43, in <module>
ani = animation.FuncAnimation(plot_object, animate, interval=1000)
File "/Users/jsmith/miniconda3/lib/python3.8/site-packages/matplotlib/animation.py", line 1656, in __init__
TimedAnimation.__init__(self, fig, **kwargs)
File "/Users/jsmith/miniconda3/lib/python3.8/site-packages/matplotlib/animation.py", line 1414, in __init__
event_source = fig.canvas.new_timer(interval=self._interval)
AttributeError: 'NoneType' object has no attribute 'canvas'
我是否需要以某种方式进一步定义plot_object,例如plot_object = FigureCanvasTkAgg(self.f,toplevel)
?
将功能hp.plotter
(分析已分析的工作目录数据)定义为plot_object的权利还吗?还是可以仅在功能动画设置中使用hp.plotter
?
也许我还需要对hp.process(data,40)
进行动画处理,因为从技术上讲,它需要处理添加的每行新数据,但是我还需要对绘图仪函数hp.plotter进行动画处理以不断更新绘图仪。我还认为我需要保持wd,m处理过的数据或数据文件本身在def=Animate(i)
下打开,但是不确定如何处理像wd,m
这样的字典数据。