【问题标题】:Python: how to make a histogram with given bins and binned data [duplicate]Python:如何使用给定的 bin 和 binned 数据制作直方图 [重复]
【发布时间】:2014-12-05 19:45:18
【问题描述】:

我想用 Python 制作一个包含分箱数据的直方图,但我不知道如何制作。我没有找到任何文档(或者我谷歌搜索错误),但我已经尝试过:

import pylab as plb

a = [1, 2, 3, 4, 5, 6] # my histogram bins
b = [1, 4, 6, 1, 3, 7] # my data

plb.hist(b, bins = a)
plb.show()

还有相关的替代品,当然也行不通。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    你给出的例子在我的电脑上运行得很好,当然它看起来不是很好。搜索食谱常用图的好地方是 Matplotlib 库:http://matplotlib.org/gallery.html。如果您想了解有关函数使用哪些参数的更多信息,可以查看文档 (http://matplotlib.org/api/pyplot_api.html?highlight=hist#matplotlib.pyplot.hist)

    如果您查看该图库并搜索直方图,您会发现此示例符合您的需求: http://matplotlib.org/examples/statistics/histogram_demo_histtypes.html

    【讨论】:

    • 这个例子确实给出了一个直方图,但不是我所期望的。上面有人发布了一个指向同一个问题的链接,其中的答案是使用 bin 作为数据并将数据作为权重。
    猜你喜欢
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    • 2015-09-19
    • 2021-05-10
    • 1970-01-01
    相关资源
    最近更新 更多