code: def freedman_diaconis_bins(a):
      
      # From http://stats.stackexchange.com/questions/798/
      a = np.asarray(a)
      h = 2 * iqr(a) / (len(a) ** (1 / 3))
  
      # fall back to sqrt(a) bins if iqr is 0
      if h == 0:
          bins = np.ceil(np.sqrt(a.size))
      else:
          bins = np.ceil((np.nanmax(a) - np.nanmin(a)) / h)
  
      return np.int(bins)
docs: Calculate number of hist bins using Freedman-Diaconis rule.