Last active
March 22, 2022 12:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working anymore