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

2024-05-01 22:09:48 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法只用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中两者都能做,就像用sns.distplot(s)绘制分布时一样,这样既可以得到kde拟合,也可以得到直方图。有办法吗?


Tags: importnumpytruepandasasnp绘制seaborn
2条回答

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

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

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)

enter image description here

相关问题 更多 >