python的pyplot画折线图

python3,脚本挂日志就能生成折线图 

import numpy as np
import matplotlib.pyplot as plt
import sys
import re

x = []
y = []
x_start = 0
x_step = 5

fp =open(sys.argv[1], 'rb')
for line in fp.readlines():
    text = line.decode()
    if "%," in text:
        #print(re.findall(r"(\d+)%",text)[0])
        x.append(int(x_start))
        x_start += x_step
        y.append(int(re.findall(r"(\d+)%",text)[0]))#取%号前的数字
    elif "interval time:" in text:
        x_step = int(re.findall(r"(\d+).",text)[0])#取小数
        print(x_step)
#print("x:"+str(x))
#print("y:"+str(y))

plt.ylim(0,100)

my_x_ticks = np.arange(0, x_start, 10)
my_y_ticks = np.arange(0, 100, 5)
plt.xticks(my_x_ticks)
plt.yticks(my_y_ticks)

plt.plot(x,y,'r--')
plt.plot(x,y,'ro-')

plt.title('load graph')
plt.xlabel('time(s)')
plt.ylabel('load(%)')
plt.grid(linestyle='-.')
plt.show()
interval time: 5.0, duration time: 100000

01-01-1970 00:04:32:   8%, < 25, 16,  9,  4,  2,  0,  0>
01-01-1970 00:04:37:   7%, < 25, 16,  8,  4,  2,  0,  0>
01-01-1970 00:04:42:   7%, < 23, 15,  8,  4,  1,  0,  0>
01-01-1970 00:04:47:   7%, < 24, 15,  9,  4,  1,  0,  0>
01-01-1970 00:04:52:   7%, < 25, 16,  8,  4,  1,  0,  0>
01-01-1970 00:04:57:   7%, < 24, 16,  8,  4,  1,  0,  0>
01-01-1970 00:05:02:   7%, < 23, 15,  8,  4,  1,  0,  0>
01-01-1970 00:05:07:   8%, < 25, 16,  9,  4,  1,  1,  0>
01-01-1970 00:05:12:   8%, < 25, 16,  9,  5,  2,  0,  0>
01-01-1970 00:05:17:   7%, < 23, 15,  8,  4,  2,  0,  0>
01-01-1970 00:05:22:   7%, < 24, 16,  9,  4,  2,  0,  0>
01-01-1970 00:05:27:   7%, < 23, 15,  8,  4,  1,  0,  0>
01-01-1970 00:05:33:   7%, < 22, 14,  8,  4,  1,  0,  0>
01-01-1970 00:05:38:   6%, < 21, 13,  8,  4,  1,  1,  0>
01-01-1970 00:05:43:   6%, < 20, 13,  7,  3,  1,  0,  0>
01-01-1970 00:05:48:   7%, < 22, 14,  8,  4,  1,  1,  0>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值