code: def freedman_diaconis_bins(a):
      """
      Calculate number of hist bins using Freedman-Diaconis rule.
      """
      from scipy.stats import iqr
  
      # From http://stats.stackexchange.com/questions/798/
      a = np.asarray(a)
      h = 2 * iqr(a, nan_policy="omit") / (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 int(bins)
  
file_path: plotnine/plotnine/stats/binning.py
imports: from __future__ import annotations
  import typing
  import numpy
  import pandas
  from ..exceptions import PlotnineError
  from ..scales.scale_discrete import scale_discrete
label_desc: Use image node_id 1 for calling a global function with example usage: freedman_diaconis_bins(a) and returns: int