Skip to content

Instantly share code, notes, and snippets.

@giannitedesco
Created December 10, 2023 10:37
Show Gist options
  • Save giannitedesco/d3e5e44aaefdf7f8719b8b8f9709abd1 to your computer and use it in GitHub Desktop.
Save giannitedesco/d3e5e44aaefdf7f8719b8b8f9709abd1 to your computer and use it in GitHub Desktop.
Boilerplate for histograms
#!/usr/bin/python
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
from math import log
from sys import argv
def hist(p: Path) -> None:
vals = [int(x) for x in p.read_text().splitlines()]
for x in [50, 75, 80, 85, 90, 95, 99, 99.9]:
pc = np.percentile(vals, x)
print(f'{x} percentile:', pc)
print('sum', sum(vals))
print('min', min(vals))
print('max', max(vals))
print('avg', sum(vals)/len(vals))
plt.hist(vals, bins=100, density=True, stacked=True, log=True)
plt.show()
def main() -> None:
for fn in argv[1:]:
hist(Path(fn))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment