Python ---chart

Posted 清明-心若淡定

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python ---chart相关的知识,希望对你有一定的参考价值。

# -*- 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(
)
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的主要内容,如果未能解决你的问题,请参考以下文章

Python开发

Python 介绍

Python学习之认识python

python初识

Python 线程池模块,Python 多线程

如何切换python版本