您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

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)
python 2022/1/1 18:38:52 有248人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶