python-pyplot直方图,标注直方图数据

话不多说。
由于自己一直忘记直方图的一些细节,经常不用,老得百度,干脆自己记下来好了。
这是直方图的写法与标注直方图的数据写法。如下

from matplotlib import pyplot as plt

x = range(1,11)
y = [84,87,78,93,26,88,74,92,69,86]
fig, ax = plt.subplots()
# 截尾平均数
means = sum(sorted(y)[1:-1])/len(y[1:-1])
b = ax.bar(x, y, label='{}'.format(means))
plt.title('Recommended song list score')
for a, b in zip(x, y):
    ax.text(a, b+1, b, ha='center', va='bottom')

plt.xlim((1,10))
plt.ylim((1,100))
plt.xticks(range(len(x)+2))
plt.xlabel('playlist number')
plt.ylabel('score')
plt.legend()
plt.show()

结果如下:
在这里插入图片描述

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值