Animation Spyder和terminal上使用动画情节的差异

Animation Spyder和terminal上使用动画情节的差异,animation,plot,terminal,spyder,live,Animation,Plot,Terminal,Spyder,Live,我能够生成一个工作的实时图形,绘制模拟实时ECG数据的值,但Spyder中的输出与使用常规终端之间存在差异。在Spyder中,它绘制了一条到1000的对角线(或我决定在这里放置的任何数字),而在terminal中则没有。我怀疑必须使用行,=ax.plot(x,np.linspace(01000100))。尝试修改或隐藏该行时,绘图失败。我的x标签的时间也有一点偏离,但当试图使它们变得真实时(与“99秒前”相比,大约每秒滴答一次),它似乎会大幅改变绘图的分辨率 import heartpy as

我能够生成一个工作的实时图形,绘制模拟实时ECG数据的值,但Spyder中的输出与使用常规终端之间存在差异。在Spyder中,它绘制了一条到1000的对角线(或我决定在这里放置的任何数字),而在terminal中则没有。我怀疑必须使用
行,=ax.plot(x,np.linspace(01000100))
。尝试修改或隐藏该行时,绘图失败。我的x标签的时间也有一点偏离,但当试图使它们变得真实时(与“99秒前”相比,大约每秒滴答一次),它似乎会大幅改变绘图的分辨率

import heartpy as hp
import numpy as np
import matplotlib.pyplot as plt

import matplotlib.animation as animation 
from collections import deque
from matplotlib.ticker import FuncFormatter





sample_rate = 25
def init():
   line.set_ydata([np.nan]*len(x))
    #line.set_ydata1([np.nan]*len(x))
   return line,

def animate(i):
    read_fname = 'temp.1D'
    datax = np.loadtxt('temp.1D')
    wd, m = hp.process(datax, 25 ) #run analysis        
    hr = wd['hr']
    yhr=np.array(hr[-1:])

#add next value
    data.append(yhr)
    line.set_ydata(data)
    
    return line,

max_x = 100
max_rand = 2000
    
data = deque(np.zeros(max_x),maxlen=max_x) #hold the last 10 values
x = np.arange(0,max_x)
    
fig, ax = plt.subplots()
ax.set_ylim(-500, max_rand)
ax.set_xlim(0, max_x-1)
line, = ax.plot(x, np.linspace(0,1000,100))
print(line)
ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{:.0f}s'.format(max_x - x - 1)))
plt.xlabel('Seconds ago')
    

        
ani = animation.FuncAnimation(fig,animate,init_func=init,interval=40,blit=True,save_count=10)


plt.show()