Skip to content

Instantly share code, notes, and snippets.

@mbjd
Created May 2, 2024 10:08
Show Gist options
  • Save mbjd/106c224d96b89a5f69feab1cd8c9041c to your computer and use it in GitHub Desktop.
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 :)
#!/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
Copy link
Author

mbjd commented May 2, 2024

so cool! this literally changed my life

@mbjd
Copy link
Author

mbjd commented May 2, 2024

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