Created
March 8, 2021 20:37
-
-
Save joocer/48e081f407ab1be7f0fdd0d6560faf2a to your computer and use it in GitHub Desktop.
single char high histogram
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
bar_chars = (' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█') | |
def _draw_histogram(bins): | |
mx = max([v for k,v in bins.items()]) | |
bar_height = (mx / 7) | |
if mx == 0: | |
return ' ' * len(bins) | |
histogram = '' | |
for k,v in bins.items(): | |
if v == 0: | |
histogram += ' ' | |
height = int(v / bar_height) + 1 | |
histogram += bar_chars[height] | |
return histogram |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment