话不多说。
由于自己一直忘记直方图的一些细节,经常不用,老得百度,干脆自己记下来好了。
这是直方图的写法与标注直方图的数据写法。如下
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()
结果如下: