<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_gen_diff( networkA, networkB, leave_out_carriers=[ 'geothermal', 'oil', 'other_non_renewable', 'reservoir', 'waste']):
 """ Plot difference in generation between two networks grouped by carrier type Parameters networkA : PyPSA network container with switches networkB : PyPSA network container without switches leave_out_carriers : list of carriers to leave out (default to all small carriers) Returns ------- Plot """

    def gen_by_c(network):
        gen = pd.concat([network.generators_t.p.mul(
                        network.snapshot_weightings, axis=0)[network.generators
                        [network.generators.control != 'Slack'].index],
                        network.generators_t.p.mul(
                        network.snapshot_weightings, axis=0)[network.generators
                        [network. generators.control == 'Slack'].index]
                        .iloc[:, 0].apply(lambda x: x if x > 0 else 0)],
                        axis=1)\
                        .groupby(network.generators.carrier,axis=1).sum()
        return gen

    gen = gen_by_c(networkB)
    gen_switches = gen_by_c(networkA)
    diff = gen_switches - gen

    colors = coloring()
    diff.drop(leave_out_carriers, axis=1, inplace=True)
    colors = [colors[col] for col in diff.columns]

    plot = diff.plot(kind='line', color=colors, use_index=False)
    plot.legend(loc='upper left', ncol=5, prop={'size': 8})
    x = []
    for i in range(0, len(diff)):
        x.append(i)
    plt.xticks(x, x)
    plot.set_xlabel('Timesteps')
    plot.set_ylabel('Difference in Generation in MW')
    plot.set_title('Difference in Generation')
    plt.tight_layout()