码迷,mamicode.com
首页 > 编程语言 > 详细

Python ---chart

时间:2018-11-09 22:03:44      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:with open   app   oat   pre   form   pandas   char   data   rcp   

# -*- coding:utf-8 -*-
import random
import matplotlib.pyplot as plt
from pylab import *                 

import pandas as pd
import numpy as np
import xlsxwriter
t_indx= pd.date_range(11/9/2018 00:00:00,periods=10,freq=s,normalize=True) 
t= []
for i in t_indx:
    t.append(str(i))
    

len_num = len(t_indx)
print"len: ", len_num

cpu=[]
mem=[]
random1 = np.random.RandomState(100)
random2 = np.random.RandomState(50)
for j in range(10):
    cpu.append(round(random1.uniform(0, 400.0),2))
    mem.append(round(random2.uniform(0, 100.0),2))


#for k in cpu:
#    print "CPU: ", k
#    
#for l in mem:
#    print "MEM: ", l
 
 
#write to file
f = open(data.txt,a)
for m in range(10):
    f.write(t[m][11:])
    f.write( )
    f.write(str(cpu[m]))
    f.write( )
    f.write(str(mem[m]))
    f.write(\n)
f.close()

data1=[]
data2=[]
data3=[]    


with open(data.txt, r) as file_to_read:
    while True:
        lines = file_to_read.readline()
        if not lines:
            break
            pass
        data1.append(lines.split( ,2)[0])
        data2.append(float(lines.split( ,2)[1]))
        data3.append(float(lines.split( ,2)[2]))


#for k in data1:
#    print k
#for k in data2:
#    print k
for k in data3:
    print k



data=[data1,data2,data3]

mpl.rcParams[font.sans-serif] = [SimHei]
times=data1
x = range(len(times))
y = data2
y1 = data3
plt.plot(x, y, marker=o, mec=r, mfc=w,label=uCPU曲线图)
plt.plot(x, y1, marker=*, ms=10,label=umemory曲线图)
plt.legend()  # 让图例生效
plt.xticks(x, times, rotation=45)
plt.margins(0)
plt.subplots_adjust(bottom=0.15)
plt.xlabel(u"time(s)时间") #X轴标签
plt.ylabel("百分比") #Y轴标签
plt.title("性能监控") #标题

plt.show()

 

Python ---chart

标签:with open   app   oat   pre   form   pandas   char   data   rcp   

原文地址:https://www.cnblogs.com/saryli/p/9937386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!