matplotlib 直方图:如何在条形图上显示计数?

编程入门 行业动态 更新时间:2024-10-07 14:32:42
本文介绍了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 直方图:如何在条形图上显示计数?

本文发布于:2023-07-18 08:15:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142744.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:直方图   条形   图上   如何在   matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!