Created
March 22, 2019 15:16
-
-
Save cmantas/c8a1974931af5329a1e3d30ab563ab4c to your computer and use it in GitHub Desktop.
A simple method plotting a Cumulative Distribution Function for a given array
This file contains hidden or 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
def cdf(data, label, show = True): | |
data_size=len(data) | |
# Set bins edges | |
data_set=sorted(set(data)) | |
bins=np.append(data_set, data_set[-1]+1) | |
# Use the histogram function to bin the data | |
counts, bin_edges = np.histogram(data, bins=bins, density=False) | |
counts=counts.astype(float)/data_size | |
# Find the cdf | |
cdf = np.cumsum(counts) | |
# Plot the cdf | |
plt.plot(bin_edges[0:-1], cdf,linestyle='--', label=label) | |
plt.ylabel('cdf') | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment