User interface 实现一个简单的CPU表
我想实现我的CPU和GPU负载的实时绘图。 我已经有了一个脚本,可以检索数据并在终端中回显它。 我现在想做的是画出这些信息,看看随时间的演变。 我不知道我是否需要python,在本例中使用哪个模块? 还有其他选择吗? 有人有实时绘图的经验吗 埃里克 以下是我到目前为止所做的User interface 实现一个简单的CPU表,user-interface,plot,real-time,User Interface,Plot,Real Time,我想实现我的CPU和GPU负载的实时绘图。 我已经有了一个脚本,可以检索数据并在终端中回显它。 我现在想做的是画出这些信息,看看随时间的演变。 我不知道我是否需要python,在本例中使用哪个模块? 还有其他选择吗? 有人有实时绘图的经验吗 埃里克 以下是我到目前为止所做的 #! /usr/bin/python import pylab import time t = 0 dt = .25 old = None if __name__ == "__main__": pylab.ion(
#! /usr/bin/python
import pylab
import time
t = 0
dt = .25
old = None
if __name__ == "__main__":
pylab.ion()
#pylab.xlabel('this is x!')
#pylab.ylabel('this is y!')
#pylab.title('My First Plot')
while True:
with open('/proc/stat') as stat:
new = map(float, stat.readline().strip().split()[1:])
if old is not None:
diff = [n - o for n, o in zip(new, old)]
idle = diff[3] / sum(diff)
pylab.clf()
pylab.plot(t,int(255 * (1 - idle)),'-b', label='cpu')
#print t,int(255 * (1 - idle))
pylab.draw()
old = new
time.sleep(dt)
t = t + dt
嗯,当我执行它时会发生一些事情,但什么也没有显示。
有什么建议吗?
谢谢,
埃里克。这看起来很有趣:虽然我没有用过,所以我不能担保它,汉克斯,我会看一看。到目前为止,我尝试使用pylab,但没有成功。