Created
May 2, 2024 10:08
-
-
Save mbjd/106c224d96b89a5f69feab1cd8c9041c to your computer and use it in GitHub Desktop.
pipe a stream of numbers into this script, get a nice plot of the cdf :)
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
#!/usr/bin/env python3 | |
# plot the cumulative distribution function of bunch of numbers | |
import numpy as np | |
import matplotlib.pyplot as pl | |
A = np.loadtxt('/dev/stdin', delimiter=',') | |
assert len(A.shape) == 1, f'Data must be one-dimensional but has shape {A.shape}' | |
A = np.sort(A) | |
ps = np.linspace(0, 1, A.shape[0]) | |
pl.plot(A, ps) | |
pl.ylabel('$P(X \leq x)$') | |
pl.xlabel('x') | |
pl.ylim([-.05, 1.05]) | |
pl.grid('on') | |
pl.show() |
mbjd, you are the lord and saviour!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so cool! this literally changed my life