Skip to content

Instantly share code, notes, and snippets.

@joocer
Created March 8, 2021 20:37
Show Gist options
  • Save joocer/48e081f407ab1be7f0fdd0d6560faf2a to your computer and use it in GitHub Desktop.
Save joocer/48e081f407ab1be7f0fdd0d6560faf2a to your computer and use it in GitHub Desktop.
single char high histogram
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