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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值