使用 Seaborn Python 绘制 CDF + 累积直方图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39297523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Plot CDF + cumulative histogram using Seaborn Python
提问by Michael
Is there a way to plot the CDF + cumulative histogram of a Pandas Series in Python using Seaborn only? I have the following:
有没有办法仅使用 Seaborn 在 Python 中绘制 Pandas 系列的 CDF + 累积直方图?我有以下几点:
import numpy as np
import pandas as pd
import seaborn as sns
s = pd.Series(np.random.normal(size=1000))
I know I can plot the cumulative histogram with s.hist(cumulative=True, normed=1)
, and I know I can then plot the CDF using sns.kdeplot(s, cumulative=True)
, but I want something that can do both in Seaborn, just like when plotting a distribution with sns.distplot(s)
, which gives both the kde fit and the histogram. Is there a way?
我知道我可以用 绘制累积直方图s.hist(cumulative=True, normed=1)
,我知道然后我可以用 绘制 CDF sns.kdeplot(s, cumulative=True)
,但我想要在 Seaborn 中可以同时做的事情,就像用 绘制分布时一样sns.distplot(s)
,它给出了 kde 拟合和直方图。有办法吗?
回答by mwaskom
回答by Sarah
You can get almost the same plot using matplotlib by using cumulative=True
and density=True
.
您可以通过使用cumulative=True
和使用 matplotlib 获得几乎相同的图density=True
。
plt.hist(x,cumulative=True, density=True, bins=30)
plt.hist(x,cumulative=True, density=True, bins=30)