Created
December 10, 2023 10:37
-
-
Save giannitedesco/d3e5e44aaefdf7f8719b8b8f9709abd1 to your computer and use it in GitHub Desktop.
Boilerplate for histograms
This file contains 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/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