<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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 ------- """


    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