RpiTempmonGraph.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:raspberrypi_tempmon 作者: gavinlyonsrepo 项目源码 文件源码
def graph_log_data(self, destlog):
        """draw a  graph of pi GPU CPU from logdata"""
        #define lists to hold data from logfile
        timelist = []
        cpulist = []
        gpulist = []

        #get data from file and put into lists
        mypath = destlog + "/" + "log.txt"
        if os.path.isfile(mypath):
            with open(mypath, 'r') as myfile:
                for line in myfile:
                    if "TS" in line:
                        timelist.append(line[5:-1])
                    if "CPU" in line:
                        cpulist.append(line[18:20])
                    if "GPU" in line:
                        gpulist.append(line[18:20])
        else:
            print("Log file not found at {}".format(mypath))
            return 1
        #parse dates format
        mydates = [dateutil.parser.parse(s) for s in timelist]
        #make graph matplotlib from logfile
        plt.xticks(rotation=25)
        plt.subplots_adjust(bottom=0.2)
        axisx = plt.gca()
        axisx.set_xticks(mydates)
        xfmt = md.DateFormatter('%m/%d %H:%M')
        axisx.xaxis.set_major_formatter(xfmt)
        axisx.xaxis.label.set_color('red')
        axisx.yaxis.label.set_color('red')
        plt.plot(mydates, cpulist, label='CPU', color='green', marker='x')
        plt.plot(mydates, gpulist, label='GPU', marker='*')
        plt.xlabel('Date time stamp (DD-MM HH:MM)')
        plt.ylabel('Temperature (degrees)')
        plt.title('ARM CPU and GPU temperature of Raspberry Pi 3', color='green')
        plt.legend(loc='upper right',
                   fancybox=True, shadow=True)
        plt.grid(True)
        plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号