使用Seaborn Python绘制CDF +累积直方图

Mic*_*ael 36 python pandas seaborn

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

import numpy as np
import pandas as pd
import seaborn as sns
s = pd.Series(np.random.normal(size=1000))
Run Code Online (Sandbox Code Playgroud)

我知道我可以绘制累积直方图s.hist(cumulative=True, normed=1),并且我知道我可以使用绘制CDF sns.kdeplot(s, cumulative=True),但我想要一些可以在Seaborn中完成的东西,就像绘制分布时一样sns.distplot(s),既给出了kde拟合,又给出了直方图.有办法吗?

mwa*_*kom 67

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • `{'cumulative':True}`可能更加惯用. (26认同)

Sar*_*rah 8

您可以通过使用cumulative=True和使用 matplotlib 获得几乎相同的图density=True

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