Welcome, guest | Sign In | My Account | Store | Cart
import numpy as np

def cli_hist(data,bins=10):
    bars = u' ▁▂▃▄▅▆▇█'
    n,_ = np.histogram(data,bins=bins)
    n2=n*(len(bars)-1)/(max(n))
    res = u" ".join( bars[i] for i in n2 )
    return res

data = np.random.random(100)    

print cli_hist(data)
# ▆ ▄ ▃ ▅ █ ▄ ▅ ▁ ▅ ▇
print cli_hist(data,bins=5)
# ▆ ▅ █ ▄ ▇

Diff to Previous Revision

--- revision 2 2012-10-18 10:06:31
+++ revision 3 2012-10-18 10:08:09
@@ -4,7 +4,7 @@
     bars = u' ▁▂▃▄▅▆▇█'
     n,_ = np.histogram(data,bins=bins)
     n2=n*(len(bars)-1)/(max(n))
-    res = " ".join( bars[i] for i in n2 )
+    res = u" ".join( bars[i] for i in n2 )
     return res
 
 data = np.random.random(100)    

History