Python:Matplotlib-概率质量函数作为直方图

Python:Matplotlib-概率质量函数作为直方图,第1张

Python:Matplotlib-概率质量函数作为直方图

据我所知

matplotlib
没有内置此功能。但是,复制起来很容易

    import numpy as np    heights,bins = np.histogram(data,bins=50)    heights = heights/sum(heights)    plt.bar(bins[:-1],heights,width=(max(bins) - min(bins))/len(bins), color="blue", alpha=0.5)

编辑:这是来自类似问题的另一种方法:

     weights = np.ones_like(data)/len(data)     plt.hist(data, bins=50, weights=weights, color="blue", alpha=0.5, normed=False)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5663712.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存