Skip to content

Instantly share code, notes, and snippets.

@cmantas
Created March 22, 2019 15:16
Show Gist options
  • Save cmantas/c8a1974931af5329a1e3d30ab563ab4c to your computer and use it in GitHub Desktop.
Save cmantas/c8a1974931af5329a1e3d30ab563ab4c to your computer and use it in GitHub Desktop.
A simple method plotting a Cumulative Distribution Function for a given array
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