python 常用画图总结

本文通过Matplotlib库创建了一张图表,展示了不同窗口大小下分布式环境中的RecoveryTime(恢复时间),重点在于8.36ms到50,000ms的时间范围。数据可视化有助于理解各延迟对性能的影响。

官方文档:https://matplotlib.org/stable/gallery/index.html

# coding=UTF-8
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
# import sys
# reload(sys)
# sys.setdefaultencoding('utf-8')


labels = ['5ms','10ms','50ms','100ms','500ms','1000ms','10000ms','20000ms','30000ms','40000ms','50000ms']
dis = [8.36, 8.67, 8.06, 12.96, 22.26, 27.77, 100.98, 152.21, 197.46, 236.11, 299.01] # cbf
# women_means = [25, 32, 34, 20, 25]

x = np.arange(len(labels))  # the label locations
width = 0.6  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x, dis, width, color='#D55E00', edgecolor='#D55E00',log=True, align='center') # for time
# rects2 = ax.bar(x + width/2, women_means, width, label='分布式') #可以设置两个柱子的比价,具体看官方文档里的example

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('time (s)') 
plt.ylim(0,1000)
ax.set_xlabel('window size')
ax.set_title('Recovery Time on Distributed (cbf)')
ax.set_xticks(x) #设置坐标轴标签上的值,显示什么字,以及字是否倾斜
ax.set_xticklabels(labels)
# ax.legend() #设置右上角图例


def autolabel(rects):
    """Attach a text label above each bar in *rects*, displaying its height."""
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')


autolabel(rects1)
# autolabel(rects2)

fig.tight_layout()

plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值