Skip to content

Instantly share code, notes, and snippets.

@pierdom
Last active March 22, 2022 12:10
Show Gist options
  • Save pierdom/5f7c5b48725f4ccbb992a4df9a17c0d4 to your computer and use it in GitHub Desktop.
Save pierdom/5f7c5b48725f4ccbb992a4df9a17c0d4 to your computer and use it in GitHub Desktop.
[CDF and PDF side by side in matplotlib] A Cumulative Distribution Function (CDF) and a Power Distribution Function (PDF) side-by-side using matplotlib's subplot and seaborn's distplot. In the example below, the dataset is a Pandas's DataFrame. #python #matplotlib #visualization #statistics #datascience
# plot hourly action rate (HAR) distribution
import matplotlib as plt
import seaborn as sns
# settings
f, axes = plt.subplots(1, 2, figsize=(18,6), dpi=320)
axes[0].set_ylabel('fraction (PDF)')
axes[1].set_ylabel('fraction (CDF)')
# left plot (PDF) # REMEMBER TO CHANGE bins, xlim PROPERLY!!
sns.distplot(
mydataframe.mycolumn, bins=5000, kde=True, axlabel='my variable',
hist_kws={"normed":True}, ax=axes[0]
).set(xlim=(0,8))
# right plot (CDF) # REMEMBER TO CHANGE bins, xlim PROPERLY!!
sns.distplot(
mydataframe.mycolumn, bins=50000, kde=False, axlabel='my variable',
hist_kws={"normed":True,"cumulative":True,"histtype":"step","linewidth":4}, ax=axes[1],
).set(xlim=(0,8),ylim=(0,1))
@charlesfg
Copy link

not working anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment