我想将我的显卡温度从文件绘制到情节
import matplotlib.pylab as pylab
temperature = 0.0
timestep = 0
logfile = file('sensorlog.txt','r')
pylab.figure(1)
pylab.xlabel('Time Steps')
pylab.ylabel('Fan Temperature')
for line in logfile:
if line[0].isdigit():
pylab.figure(1)
temperature = float(line.split(',')[4].strip())
timestep = timestep + 1
#print 'timestep: ' + str(timestep) + '| temperature: ' + str(temperature) /works till here D:
pylab.plot(float(timestep), float(temperature), color='green')
pylab.show()
出局图只是空的,每个轴的缩放似乎已经在正确的维度。
我正在阅读的文本文件的小例子,它就像这样(大约12000个条目)
Date , GPU Core Clock [MHz] , GPU Memory Clock [MHz] , GPU Temperature [°C] , Fan Speed (%) [%] , Fan Speed (RPM) [RPM] , GPU Load [%] , GPU Temp. #1 [°C] , GPU Temp. #2 [°C] , GPU Temp. #3 [°C] , Memory Usage (Dedicated) [MB] , Memory Usage (Dynamic) [MB] , VDDC [V] ,
2014-11-17 20:21:38 , 100.0 , 150.0 , 39.0 , 41 , - , 0 , 39.5 , 35.5 , 40.5 , 476 , 173 , 0.950 ,
2014-11-17 20:21:39 , 100.0 , 150.0 , 40.0 , 41 , - , 6 , 39.5 , 35.0 , 40.5 , 476 , 173 , 0.950 ,
答案 0 :(得分:0)
您似乎想要在此时绘制一个点。不要那样做:将所有数据收集到一个数组中(从日志文件中),然后一次性绘制所有数据。所以,在你的for循环之外做所有的绘图:
import matplotlib.pylab as pylab
logfile = file('sensorlog.txt','r')
pylab.figure(1)
pylab.xlabel('Time Steps')
pylab.ylabel('Fan Temperature')
temperatures = []
for line in logfile:
if line[0].isdigit():
temperatures.append(float(line.split(',')[4].strip()))
timesteps = np.arange(len(temperatures))
pylab.plot(timesteps, temperatures, color='green')
pylab.show()
(如果您的timesteps
增加1,从0开始,就像这里一样,您甚至可以做到:
pylab.plot(temperatures, color='green')
和matplotlib将填写x值。)