Plot CDF + cumulative histogram using Seaborn
Asked Answered
C

2

59

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?

Casey answered 2/9, 2016 at 17:3 Comment(0)
I
106
import numpy as np
import seaborn as sns

x = np.random.randn(200)
stat = "count"  # or proportion
sns.histplot(x, stat=stat, cumulative=True, alpha=.4)
sns.ecdfplot(x, stat=stat)

enter image description here

Intramural answered 3/9, 2016 at 12:17 Comment(0)
N
11

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)

Nationwide answered 17/7, 2019 at 1:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.