Python Pylab图不显示任何绘图点

Python Pylab图不显示任何绘图点,python,matplotlib,plot,Python,Matplotlib,Plot,我想将图形卡的温度从一个文件打印到一个绘图 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():

我想将图形卡的温度从一个文件打印到一个绘图

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   ,

看起来您希望一次绘制一个点。不要这样做:从日志文件中将所有数据收集到一个数组中,然后一次绘制所有数据。因此,在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()
如果您的时间步长增加1,从0开始,就像这里一样,您甚至可以简单地执行以下操作:

pylab.plot(temperatures, color='green')

matplotlib将填充x值。

看起来您希望一次绘制一个点。不要这样做:从日志文件中将所有数据收集到一个数组中,然后一次绘制所有数据。所以,在for循环之外进行所有绘图。非常感谢,这就成功了!我真的试着一次画一个点。