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.

Revisions

  1. cmantas created this gist Mar 22, 2019.
    21 changes: 21 additions & 0 deletions cdf.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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()