code: def calc_bins(n, min_val, max_val, h=None, binwidth=None):
      
      if not h:
          h = max(10, math.log(n + 1, 2))
      if binwidth == 0:
          binwidth = 0.1
      if binwidth is None:
          binwidth = (max_val - min_val) / h
      for b in drange(min_val, max_val, step=binwidth, include_stop=True):
          if b.is_integer():
              yield int(b)
          else:
              yield b
docs: Calculate number of bins for the histogram