docs: def plot_quantile_returns_bar(mean_ret_by_q,
                                by_group=False,
                                ylim_percentiles=None,
                                ax=None):
      """
      Plots mean period wise returns for factor quantiles.
  
      Parameters
      ----------
      mean_ret_by_q : pd.DataFrame
          DataFrame with quantile, (group) and mean period wise return values.
      by_group : bool
          Disaggregated figures by group.
      ylim_percentiles : tuple of integers
          Percentiles of observed data to use as y limits for plot.
      ax : matplotlib.Axes, optional
          Axes upon which to plot.
  
      Returns
      -------
      ax : matplotlib.Axes
          The axes that were plotted on.
      """
  
      mean_ret_by_q = mean_ret_by_q.copy()
  
      if ylim_percentiles is not None:
          ymin = (np.nanpercentile(mean_ret_by_q.values,
                                   ylim_percentiles[0]) * DECIMAL_TO_BPS)
          ymax = (np.nanpercentile(mean_ret_by_q.values,
                                   ylim_percentiles[1]) * DECIMAL_TO_BPS)
      else:
          ymin = None
          ymax = None
  
      if by_group:
          num_group = len(
              mean_ret_by_q.index.get_level_values('group').unique())
  
          if ax is None:
              v_spaces = ((num_group - 1) // 2) + 1
              f, ax = plt.subplots(v_spaces, 2, sharex=False,
                                   sharey=True, figsize=(18, 6 * v_spaces))
              ax = ax.flatten()
  
          for a, (sc, cor) in zip(ax, mean_ret_by_q.groupby(level='group')):
              (cor.xs(sc, level='group')
                  .multiply(DECIMAL_TO_BPS)
                  .plot(kind='bar', title=sc, ax=a))
  
              a.set(xlabel='', ylabel='Mean Return (bps)',
                    ylim=(ymin, ymax))
  
          if num_group < len(ax):
              ax[-1].set_visible(False)
  
          return ax
  
      else:
          if ax is None:
              f, ax = plt.subplots(1, 1, figsize=(18, 6))
  
          (mean_ret_by_q.multiply(DECIMAL_TO_BPS)
              .plot(kind='bar',
                    title="Mean Period Wise Return By Factor Quantile", ax=ax))
          ax.set(xlabel='', ylabel='Mean Return (bps)',
                 ylim=(ymin, ymax))
  
          return ax