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 = " ".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 1 2012-10-18 10:00:59
+++ revision 2 2012-10-18 10:06:31
@@ -4,11 +4,12 @@
     bars = u' ▁▂▃▄▅▆▇█'
     n,_ = np.histogram(data,bins=bins)
     n2=n*(len(bars)-1)/(max(n))
-    for i in n2:
-        print bars[i],
-    print
+    res = " ".join( bars[i] for i in n2 )
+    return res
 
 data = np.random.random(100)    
 
-cli_hist(data)
-cli_hist(data,bins=5)
+print cli_hist(data)
+# ▆ ▄ ▃ ▅ █ ▄ ▅ ▁ ▅ ▇
+print cli_hist(data,bins=5)
+# ▆ ▅ █ ▄ ▇

History