简体   繁体   中英

Plot CDF + cumulative histogram using Seaborn Python

Is there a way to plot the CDF + cumulative histogram of a Pandas Series in Python using Seaborn only? I have the following:

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?

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)

在此处输入图片说明

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM