分布历史图中的加权箱 [英] Weighted bins in a distribution hist plot
本文介绍了分布历史图中的加权箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种绘制分布直方图的方法,其中 y轴
代表每个垃圾箱的项目总数(而不仅仅是计数).
I'm looking for a way to plot a distribution histogram, with the y-axis
representing the total number of items for each bin (and not just the count).
下图示例:
- 在左侧,有55家代理商出售了20到30套房屋
- 在右边,已售出20到30套房屋的代理商代表已售出1100套房屋
这并不像看起来那么琐碎,因为不能简单地将每个垃圾箱的数量乘以垃圾箱的价值(也许在20-30个垃圾箱中,有54家代理商卖出21家,而1家卖出了29家).
It's not as trivial as it looks because one can't simply multiply each bin's count by the bin's value (maybe in the 20-30 bin, there are 54 agencies who sold 21 are 1 who sold 29).
问题:
- 这种图表的名称是什么(右边的那个)?
- 有没有办法在
matplotlib
或seaborn
中本地绘制它?
- What is the name of such a chart (the one on the right)?
- Is there a way to plot it natively in
matplotlib
orseaborn
?
推荐答案
您要使用 weight
kwarg(请参阅请参见).
You want to use the weight
kwarg (see numpy docs) which is passed through ax.hist
(see).
类似
fig, ax = plt.subplots()
ax.hist(num_sold, bins, weights=num_sold)
这篇关于分布历史图中的加权箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文