我通过Paramiko从远程设备收集的数据中提供以下动画。 如果我理解动画间隔的概念,值为1000秒,动画应该每1000毫秒更新一次图,x轴应该以秒为单位显示实时单位。
在测量动画功能和内部的不同部分之后,看起来动画功能执行时间超过1秒,并且动画部分会拉动inf。远程设备占用大部分时间。
拉动功能需要超过一秒钟并不重要,最重要的是绘制的信息对应于x轴中的第二个单位。
如果确保绘图将在X轴上显示实时单位(在我的情况下为秒)并在Y轴上显示y值,即使读取过程花费的时间超过时间单位?
def GetInfo(stdout):
...
def init():
line.set_data(\[\], \[\])
return line,
def animate(i):
### I
tRefAnim = time.time()
global penQ
global halfTimer
global tRef
### II
tRefSess = time.time()
Session = CParam(IP,login , hostname, sshpass)
Session.SendCmd(command)
DAMINFO = GetInfo(Session.stdout)
print "Device Session time = " + "{0:.3f}".format(time.time()-tRefSess)
### III
tRefAnn = time.time()
...
print "Conditional annotations = " + "{0:.3f}".format(time.time()-tRefAnn)
### IV
tRefDraw = time.time()
# Collect data into x and y lists
xdata.append(i)
ydata.append(y)
xmin, xmax = ax.get_xlim()
ymin, ymax = ax.get_ylim()
###changing the xmax dynamically
if i >= xmax:
ax.set_xlim(xmin, xmax+(xmax/2))
ax.figure.canvas.draw()
###changing the ymax dynamically
if y >= ymax:
ax.set_ylim(ymin, y+(y/10))
ax.figure.canvas.draw()
#line.set_data(x, y)
line.set_data(xdata, ydata)
print "Drawing time = " + "{0:.3f}".format(time.time()-tRefDraw)
print "animate time = " + "{0:.3f}".format(time.time()-tRefAnim)
return line,
# initializing parameters
...
#initial max x axis
init_xlim = 5
init_ylim = 3500
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, init_xlim), ylim=(0, init_ylim))
ax.grid()
line, = ax.plot(\[\], \[\], lw=2)
#x = np.linspace(4, 5, 1000)
xdata, ydata = \[\], \[\]
anim = animation.FuncAnimation(fig, animate, init_func=init,frames=2000, interval=1000, blit=False)
plt.show()][1]
时间测量的结果
Drawing time = 0.000
animate time = 1.149
Device Session time = 1.167
Conditional annotations = 0.000
Drawing time = 0.000
animate time = 1.168
Device Session time = 1.059
Conditional annotations = 0.000
Drawing time = 0.000
animate time = 1.060
Device Session time = 1.072
Conditional annotations = 0.000
Drawing time = 0.000
animate time = 1.073
Device Session time = 1.049
Conditional annotations = 0.000
Drawing time = 0.069
animate time = 1.119
Device Session time = 1.155
Conditional annotations = 0.000
Drawing time = 0.000
animate time = 1.156
答案 0 :(得分:0)
我设法让绘图显示时间,精度为+/- 300毫秒。
但是,显然这是一种解决方法。 我对任何其他建议持开放态度。