Plot CDF + cumulative histogram using Seaborn Python

PythonPandasSeaborn

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

You can get almost the same plot using matplotlib by using cumulative=True and density=True.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichaelView Question on Stackoverflow
Solution 1 - PythonmwaskomView Answer on Stackoverflow
Solution 2 - PythonSarahView Answer on Stackoverflow