docs: def plot_composition(df, intervals, axes=None):
      """
      Plot time series of generics and label underlying instruments which
      these series are composed of.
  
      Parameters:
      -----------
      df: pd.DataFrame
          DataFrame of time series to be plotted. Each column is a generic time
          series.
      intervals: pd.DataFrame
          A DataFrame including information for when each contract is used in the
          generic series.
          Columns are['contract', 'generic', 'start_date', 'end_date']
      axes: list
          List of matplotlib.axes.Axes
  
      Example
      -------
      >>> import mapping.plot as mplot
      >>> import pandas as pd
      >>> from pandas import Timestamp as TS
      >>> idx = pd.date_range("2017-01-01", "2017-01-15")
      >>> rets_data = pd.np.random.randn(len(idx))
      >>> rets = pd.DataFrame({"CL1": rets_data, "CL2": rets_data}, index=idx)
      >>> intervals = pd.DataFrame(
      ...   [(TS("2017-01-01"), TS("2017-01-05"), "2017_CL_F", "CL1"),
      ...    (TS("2017-01-05"), TS("2017-01-15"), "2017_CL_G", "CL1"),
      ...    (TS("2017-01-01"), TS("2017-01-12"), "2017_CL_G", "CL2"),
      ...    (TS("2017-01-10"), TS("2017-01-15"), "2017_CL_H", "CL2")],
      ...  columns=["start_date", "end_date", "contract", "generic"])
      >>> mplot.plot_composition(rets, intervals)
      """
  
      generics = df.columns
      if (axes is not None) and (len(axes) != len(generics)):
          raise ValueError("If 'axes' is not None then it must be the same "
                           "length as 'df.columns'")
  
      if axes is None:
          _, axes = plt.subplots(nrows=len(generics), ncols=1)
          if len(generics) == 1:
              axes = [axes]
  
      for ax, generic in zip(axes, generics):
          ax.plot(df.loc[:, generic], label=generic)
          # no legend line to avoid clutter
          ax.legend(loc='center right', handlelength=0)
          dates = intervals.loc[intervals.loc[:, "generic"] == generic,
                                ["start_date", "end_date", "contract"]]
          date_ticks = set(
              dates.loc[:, "start_date"].tolist() +
              dates.loc[:, "end_date"].tolist()
          )
          xticks = [ts.toordinal() for ts in date_ticks]
          xlabels = [ts.strftime("%Y-%m-%d") for ts in date_ticks]
          ax.set_xticks(xticks)
          ax.set_xticklabels(xlabels)
          y_top = ax.get_ylim()[1]
          count = 0
          # label and colour each underlying
          for _, dt1, dt2, instr in dates.itertuples():
              if count % 2:
                  fc = "b"
              else:
                  fc = "r"
              count += 1
              ax.axvspan(dt1, dt2, facecolor=fc, alpha=0.2)
              x_mid = dt1 + (dt2 - dt1) / 2
              ax.text(x_mid, y_top, instr, rotation=45)
  
      return axes