code: def plot_haplotype_frequencies(h, palette='Paired', singleton_color='w',
                                 ax=None):
      
  
      import matplotlib.pyplot as plt
      import seaborn as sns
  
      # check inputs
      h = HaplotypeArray(h, copy=False)
  
      # setup figure
      if ax is None:
          width = plt.rcParams['figure.figsize'][0]
          height = width / 10
          fig, ax = plt.subplots(figsize=(width, height))
          sns.despine(ax=ax, left=True)
  
      # count distinct haplotypes
      hc = h.distinct_counts()
  
      # setup palette
      n_colors = np.count_nonzero(hc > 1)
      palette = sns.color_palette(palette, n_colors)
  
      # paint frequencies
      x1 = 0
      for i, c in enumerate(hc):
          x2 = x1 + c
          if c > 1:
              color = palette[i]
          else:
              color = singleton_color
          ax.axvspan(x1, x2, color=color)
          x1 = x2
  
      # tidy up
      ax.set_xlim(0, h.shape[1])
      ax.set_yticks([])
  
      return ax
docs: Plot haplotype frequencies.
  
      Parameters
      ----------
      h : array_like, int, shape (n_variants, n_haplotypes)
          Haplotype array.
      palette : string, optional
          A Seaborn palette name.
      singleton_color : string, optional
          Color to paint singleton haplotypes.
      ax : axes, optional
          The axes on which to draw. If not provided, a new figure will be
          created.
  
      Returns
      -------
      ax : axes