简体   繁体   English

Pylab图显示无图点

[英]Pylab plot shows no plot points

i wanted to plot my graphics card temps from a file to a 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():
        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()

The outcoming plot is just empty, the scaling of each axis seems to be in the right dimension already. 即将结束的图是空的,每个轴的缩放比例似乎已经在正确的尺寸上。

Small example of the textfile i am reading in, it just goes on like this (for approx 12000 entries) 我正在阅读的文本文件的一个小示例,它像这样继续进行(大约有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   ,

It appears you want to plot one point at the time. 您似乎想一次绘制一个点。 Don't do that: collect all the data into an array (from the logfile), then plot that all at once. 不要这样做:将所有数据(从日志文件中)收集到一个数组中,然后一次绘制所有数据。 So, do all the plotting outside your for loop: 因此,在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()

(If your timesteps are increasing by 1, starting at 0, like here, you can even do simply: (如果您的timesteps从0开始增加1,就像这里一样,您甚至可以执行以下操作:

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

and matplotlib will fill in the x-values.) 和matplotlib将填充x值。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM