Files
zoeyyyzou ae654e1dc8 update
2021-09-23 16:10:08 +08:00

57 lines
2.0 KiB
Python

import csv
import os
import sys
import numpy as np
import matplotlib.pyplot as plt
# 丢包个数曲线代码
# 实验0和实验1的五个场景
# 一张图里包括DSCCP和PCON的曲线
# 注:在绘制实验1的场景1.5 DSCCP-PCON 的曲线时要在第50行去掉注释
def getXY(fileName: str, target: str, faceId: str, quota: str):
x = []
y = []
fileName = os.getcwd() + '/data/' + fileName
with open(fileName, "r") as file:
lines = file.readlines()
for line in lines:
item = line.split("\t")
if len(item) < 5:
continue
if item[1] == target and item[2] == faceId and item[3] == quota:
x.append(float(item[0]))
y.append(float(item[4]))
return x, y
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python drop.py <filename_DSCCP> <filename_PCON>")
exit(0)
filename1, filename2 = sys.argv[1], ""
x1, y1 = getXY(filename1, "R2", "combined", "Drop")
y2 = y1
if len(sys.argv) == 3:
filename2 = sys.argv[2]
x2, y2 = getXY(filename2, "R2", "combined", "Drop")
# l1 = plt.plot(x1, y1, 'r', label='DSCCP', linestyle='-.', marker='+') # qjm
l1 = plt.scatter(x1, y1, c='r', label='DSCCP', marker='+', s=40) # 散点图 bh
if len(sys.argv) == 3:
# l2 = plt.plot(x2, y2, 'g', label='PCON', linestyle='-.', marker='x') # qjm
l2 = plt.scatter(x2, y2, c='g', label='PCON', marker='x', s=15) # 散点图
plt.xlim(0)
plt.ylim(0, max(5, int(max(y1 + y2)) + 1))
# plt.ylim(0, 1000) # 专用于画1.5
plt.title("DSCCP" if len(sys.argv) == 2 else "")
plt.xlabel('Time(s)')
plt.ylabel('Loss Packets')
plt.legend(loc=1)
# save pictures -bh
full_path = os.getcwd() + "/pictures_loss/" + filename1+'-'+filename2 + ".png"
# full_path = os.getcwd() + "/test/" + filename1 + '-' + filename2 + ".png"
plt.savefig(full_path, dpi=960) # 存储路径+设置图片分辨率dpi=960