def hist(xs, range=None, margin=<NUM_LIT:10>, width=None):
if width is None:<EOL><INDENT>width = terminal.width()<EOL><DEDENT>n_bins = width - (<NUM_LIT:2> * (margin + <NUM_LIT:1>))<EOL>xs = np.array(xs)<EOL>finite = np.isfinite(xs)<EOL>finite_xs = xs[finite]  <EOL>hist_values, bin_edges = np.histogram(finite_xs, bins=n_bins, density=True, range=range)<EOL>hist_heights = hist_values / max(hist_values)<EOL>hist_chars = (hist_heights * (len(terminal.bars) - <NUM_LIT:1>)).astype(int)<EOL>cells = [terminal.bars[hist_char] for hist_char in hist_chars]<EOL>print(format_number_line(cells, bin_edges[<NUM_LIT:0>], bin_edges[-<NUM_LIT:1>], margin=margin))<EOL>if not finite.all():<EOL><INDENT>nonfinite_xs = xs[~finite]<EOL>neginf = np.isneginf(nonfinite_xs)<EOL>nan = np.isnan(nonfinite_xs)<EOL>posinf = np.isposinf(nonfinite_xs)<EOL>print('<STR_LIT>' % (<EOL>('<STR_LIT>' % np.count_nonzero(neginf) if neginf.any() else '<STR_LIT>').rjust(margin),<EOL>('<STR_LIT>' % np.count_nonzero(nan) if nan.any() else '<STR_LIT>').center(len(cells)),<EOL>('<STR_LIT>' % np.count_nonzero(posinf) if posinf.any() else '<STR_LIT>').ljust(margin)<EOL>))<EOL><DEDENT>
xs: array of numbers, preferably an np.array, can contain nans, infinities
range: (minimum, maximum) tuple of numbers (defaults to (min, max) of xs)
margin: number of characters to use for the min-max labels (default: 10)
width: number of characters that will fit in a row (defaults to your terminal width)

Example:

>>> import scipy.stats
>>> draws = scipy.stats.norm.rvs(size=100, loc=100, scale=10)
>>> hist(draws, margin=5)