Created
          September 29, 2014 13:52 
        
      - 
      
- 
        Save joezuntz/2f3bdc2ab0ea59229907 to your computer and use it in GitHub Desktop. 
    Plot a numpy histogram vertically in text
  
        
  
    
      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
    
  
  
    
  | import numpy as np | |
| def ascii_hist(x, bins): | |
| N,X = np.histogram(x, bins=bins) | |
| total = 1.0*len(x) | |
| width = 50 | |
| nmax = N.max() | |
| for (xi, n) in zip(X,N): | |
| bar = '#'*int(n*1.0*width/nmax) | |
| xi = '{0: <8.4g}'.format(xi).ljust(10) | |
| print '{0}| {1}'.format(xi,bar) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Python3, with fixed indentation, and default for bins (because this is a top google result for "numpy ascii histogram")