Python的matplot进行画折线图

# encoding=utf-8

import matplotlib.pyplot as plt

from pylab import *                            

mpl.rcParams['font.sans-serif'] = ['SimHei']

lines=[]

#ori_hit=[]

FIFO=[]

CLOCK=[]

LRU=[]

LRU_2=[]

LFU=[]

LeCaR=[]

ARC=[]

GDS=[]

GDSF=[]

Optimal=[]

f = open('/Users/guanqiming/Desktop/total1.txt')

#i=0;

 

for line in f:

    line = line.strip('\n')

    line = line.split(',')

    lines.append(int(float(line[0])))

    FIFO.append(round(float(line[10]),3)-round(float(line[1]),3))

    CLOCK.append(round(float(line[10]),3)-round(float(line[2]),3))

    LRU.append(round(float(line[10]),3)-round(float(line[3]),3))

    LRU_2.append(round(float(line[10]),3)-round(float(line[4]),3))

    LFU.append(round(float(line[10]),3)-round(float(line[5]),3))

    LeCaR.append(round(float(line[10]),3)-round(float(line[6]),3))

    ARC.append(round(float(line[10]),3)-round(float(line[7]),3))

    GDS.append(round(float(line[10]),3)-round(float(line[8]),3))

    GDSF.append(round(float(line[10]),3)-round(float(line[9]),3))

#Optimal.append(round(float(line[10]),2))

'''

for line in f:

    line = line.strip('\n')

    line = line.split(',')

    lines.append(int(float(line[0])))

    FIFO.append(round(float(line[1]),2))

    CLOCK.append(round(float(line[2]),2))

    LRU.append(round(float(line[3]),2))

    LRU_2.append(round(float(line[4]),2))

    LFU.append(round(float(line[5]),2))

    LeCaR.append(round(float(line[6]),2))

    ARC.append(round(float(line[7]),2))

    GDS.append(round(float(line[8]),2))

    GDSF.append(round(float(line[9]),2))

    Optimal.append(round(float(line[10]),2))

'''

f.close

x = range(len(lines))

#y = ori_hit

#y1=my_hit

plt.figure(figsize=(12, 12))

plt.plot(x, FIFO, marker='.',color='wheat', ms=10,label=u'FIFO')

plt.plot(x, CLOCK, marker='.',color='violet', ms=10,label=u'CLOCK')

plt.plot(x, LRU, marker='.',color='red', ms=10,label=u'LRU')

plt.plot(x, LRU_2, marker='.',color='blue', ms=10,label=u'LRU_2')

plt.plot(x, LFU, marker='.', color='grey',ms=10,label=u'LFU')

plt.plot(x, LeCaR, marker='.',color='lightsteelblue', ms=10,label=u'LeCaR')

plt.plot(x, ARC, marker='.',color='yellow', ms=10,label=u'ARC')

plt.plot(x, GDS, marker='.',color='peru', ms=10,label=u'GDS')

plt.plot(x, GDSF, marker='.',color='green', ms=10,label=u'GDSF')

#plt.plot(x, Optimal, marker='.',color='skyblue', ms=10,label=u'Optimal')

#pl.xlim(-1, 11)  # 限定横轴的范围

plt.ylim(0, 0.3 )

#pl.ylim(-1, 110)  # 限定纵轴的范围

#plt.plot(x, y, marker='o', mec='r', mfc='w',label=u'ori_hit')

# 设置数字标签

#ti=0

#for a, b in zip(x, y):

#    if ti%2==0:

#       plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

#   ti=ti+1

#plt.plot(x, y1, marker='.', ms=10,label=u'my_hit')

#ti=0

'''

for a, b in zip(x, Optimal):

    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

'''

for a, b in zip(x, LRU):

    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

for a, b in zip(x, GDSF):

    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

    #for a, b in zip(x, LFU):

#    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

#for a, b in zip(x, LeCaR):

#    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

#for a, b in zip(x, ARC):

#    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

for a, b in zip(x, Optimal):

    plt.text(a, b, b, ha='center', va='bottom', fontsize=10)

 

plt.legend(loc='left', fontsize=10)  # 让图例生效

plt.xticks(x, lines, rotation=90)

plt.margins(0)

plt.subplots_adjust(bottom=0.15)

plt.xlabel(u"Capacity/GB") #X轴标签

plt.ylabel("hitting accuracy") #Y轴标签

plt.title("Byte Hit Rate diff Chart") #标题

plt.show()

你可能感兴趣的:(python)