Skip to content

Instantly share code, notes, and snippets.

@clintval
Created March 20, 2017 05:45
Show Gist options
  • Save clintval/5d4e0043cb04941ebbc7d22281762598 to your computer and use it in GitHub Desktop.
Save clintval/5d4e0043cb04941ebbc7d22281762598 to your computer and use it in GitHub Desktop.
A Python port of spark: https://github.com/holman/spark
def spark(arr):
if len(arr) <= 1:
return '▅'
elif min(arr) == max(arr):
return ''.join(['▅' for _ in arr])
ticks = ('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
norm = [round(7 * (x - min(arr)) / (max(arr) - min(arr))) for x in arr]
return ''.join([ticks[int(num)] for num in norm])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment