【问题标题】:Tricks to get reverse-order cumulative histogram in matplotlib在 matplotlib 中获取逆序累积直方图的技巧
【发布时间】:2015-05-07 12:43:37
【问题描述】:

我想知道是否有一个(更好的)技巧来反转 matplotlib 中的累积直方图。

假设我有一些分数在 0.0 到 1.0 之间,其中 1.0 是最好的分数。现在,我有兴趣绘制出有多少样本高于某个分数阈值。

import numpy as np
import matplotlib.pyplot as plt

d = np.random.normal(size=1000)
d = (d - d.min()) / (d.max() - d.min())

plt.hist(d, 50, histtype="stepfilled", alpha=.7)

默认情况下,matplotlib 将绘制累积直方图,如“样本数

plt.hist(d, 50, histtype="stepfilled", alpha=.7, cumulative=True)

我真正想要的是累积直方图不显示“样本数 = 分数”

我可以这样做,但是我将如何摆脱 x 轴上的“减号”?

plt.hist(d-1, 50, histtype="stepfilled", alpha=.7, cumulative=True)

有更好的想法吗?

【问题讨论】:

    标签: python matplotlib histogram cumulative-frequency


    【解决方案1】:

    很确定您可以在函数调用中使用cumulative=-1

    plt.hist(d, 50, histtype="stepfilled", alpha=.7, cumulative=-1)
    

    来自 matplotlib hist() 文档:

    如果累计计算结果小于 0(例如,-1),则累计方向相反。

    看看第三个示例图片here;我认为它可以满足您的需求。

    【讨论】:

    • 谢谢,这正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2013-08-23
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    相关资源
    最近更新 更多