【问题标题】:Plot CDF + cumulative histogram using Seaborn Python使用 Seaborn Python 绘制 CDF + 累积直方图
【发布时间】:2017-01-10 20:56:15
【问题描述】:

有没有办法仅使用 Seaborn 在 Python 中绘制熊猫系列的 CDF + 累积直方图?我有以下内容:

import numpy as np
import pandas as pd
import seaborn as sns
s = pd.Series(np.random.normal(size=1000))

我知道我可以使用 s.hist(cumulative=True, normed=1) 绘制累积直方图,然后我知道我可以使用 sns.kdeplot(s, cumulative=True) 绘制 CDF,但我想要在 Seaborn 中两者都可以做到的东西,就像使用 @987654324 绘制分布一样@,它给出了 kde 拟合和直方图。有什么办法吗?

【问题讨论】:

    标签: python pandas seaborn


    【解决方案1】:
    import numpy as np
    import seaborn as sns
    
    x = np.random.randn(200)
    kwargs = {'cumulative': True}
    sns.distplot(x, hist_kws=kwargs, kde_kws=kwargs)
    

    【讨论】:

      【解决方案2】:

      您可以使用 cumulative=Truedensity=True 使用 matplotlib 获得几乎相同的绘图。

      plt.hist(x,cumulative=True, density=True, bins=30)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-25
        • 1970-01-01
        • 2019-04-09
        • 2017-08-26
        • 1970-01-01
        • 2015-12-05
        相关资源
        最近更新 更多