Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形。
3.1.1 属性设置函数
3.1.2 属性获取函数
3.1.3 辅助线函数
3.1.4 绘图函数
3.1.5 清除函数
Axes类
将pyplot API封装成对象的成员函数,建议使用这些成员函数,更加利于理解绘图过程
import re
import numpy as np
import matplotlib.pyplot as plt
def extract_time(filename):
handle = open(filename)
handle.readline()
handle.readline()
handle.readline()
line = handle.readline()
all_time = []
while line:
cqe_time_stamp_tuple = re.findall(r'\d+', line)
all_time.append(int(cqe_time_stamp_tuple[-1]))
line = handle.readline()
all_time.sort()
return all_time
def heterogeneous_plot(h_time, i_time):
pct_axis = 1. * np.arange(len(h_time)) / (len(h_time) - 1)
#绘制第一条线并设置图例
plt.plot(h_time, pct_axis, label="with_bg_flow")
#绘制第二条线并设置图例
plt.plot(i_time, pct_axis, label="without_bg_flow")
#设置图例显示属性
plt.legend(loc='center right', fontsize='large')
#设置图表标题
plt.title("CDF of Small Flow")
#设置x/y轴标题
plt.xlabel("Latency(us)")
plt.ylabel("CDF(%)")
plt.show()
if __name__ == "__main__":
h_time_data = extract_time("1_tmp_data/100000_OUTPUT")
i_time_data = extract_time("2_tmp_data/100000_OUTPUT")
heterogeneous_plot(h_time_data, i_time_data)
individual_plot(h_time_data, i_time_data)
[1] matplot.pyplot api documents[https://matplotlib.org/api/pyplot_summary.html]
[2] matplot.axes[https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes]
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有