python提取log文件內(nèi)容并畫出圖表
更新時間:2019年07月08日 14:41:37 作者:caimagic
這篇文章主要介紹了python提取log文件內(nèi)容并畫出圖表,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
之前在excel里面分析log數(shù)據(jù),簡直日了*了。 現(xiàn)在用python在處理日志數(shù)據(jù).
主要涉及 matplotlib,open和循環(huán)的使用。
日志內(nèi)容大致如下
2016-10-21 21:07:59,787 [7 MainWindowForm]INFO: update time 136.6314 2016-10-21 21:07:59,908 [7 KinectServer]INFO: lClientSockets[0] elapsed time 16. 2016-10-21 21:07:59,918 [7 KinectServer]INFO: lClientSockets[1] elapsed time 107. 2016-10-21 21:07:59,929 [7 MainWindowForm]INFO: update time 135.1311 2016-10-21 21:08:00,039 [7 KinectServer]INFO: lClientSockets[0] elapsed time 14. 2016-10-21 21:08:00,045 [7 KinectServer]INFO: lClientSockets[1] elapsed time 103. 2016-10-21 21:08:00,053 [7 MainWindowForm]INFO: update time 118.1132
python處理代碼
import matplotlib.pyplot as plt input = open('serverlog.txt', 'r') rangeUpdateTime = [0.0] for line in input: line = line.split() if 'update' in line: rangeUpdateTime.append(float(line[-1])) plt.figure('frame time') plt.subplot(211) plt.plot(rangeUpdateTime, '.r',) plt.grid(True) plt.subplot(212) plt.plot(rangeUpdateTime) plt.grid(True) plt.show()
結果
真心是又好又快出結果^_^
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
python機器學習Github已達8.9Kstars模型解釋器LIME
這篇文章主要為大家介紹了Github已達8.9Kstars的最佳模型解釋器LIME的使用示例及功能詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11Python連接達夢數(shù)據(jù)庫的實現(xiàn)示例
本文主要介紹了Python連接達夢數(shù)據(jù)庫的實現(xiàn)示例,dmPython是DM提供的依據(jù)Python DB API version 2.0中API使用規(guī)定而開發(fā)的數(shù)據(jù)庫訪問接口,使Python應用程序能夠對DM數(shù)據(jù)庫進行訪問2023-12-12