matplotlib 直方图:如何在条形图上显示计数? [英] matplotlib histogram: how to display the count over the bar?

查看:111
本文介绍了matplotlib 直方图:如何在条形图上显示计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 matplotlib 的 hist 函数,如何让它显示条形图上每个 bin 的计数?

With matplotlib's hist function, how can one make it display the count for each bin over the bar?

例如

import matplotlib.pyplot as plt
data = [ ... ] # some data
plt.hist(data, bins=10)

我们如何使每个 bin 中的计数显示在其条形上?

How can we make the count in each bin display over its bar?

推荐答案

好像hist不行,可以这样写:

it seems hist can't do this,you can write some like :

your_bins=20
data=[]
arr=plt.hist(data,bins=your_bins)
for i in range(your_bins):
    plt.text(arr[1][i],arr[0][i],str(arr[0][i]))

这篇关于matplotlib 直方图:如何在条形图上显示计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆