//  [python]
def make_loss_plot(percentiles, loss2, gain2, dates, befores, afters, name):
    mean_loss18 = np.mean(percentiles[:, loss2 == 1], axis = (1))
    mean_loss19 = np.mean(percentiles[:, loss2 == 2], axis = (1))
    mean_loss20 = np.mean(percentiles[:, loss2 == 3], axis = (1))
    mean_loss21 = np.mean(percentiles[:, loss2 == 4], axis = (1))
    mean_loss22 = np.mean(percentiles[:, loss2 == 5], axis = (1))
    #mean_nochange_tree = np.mean(percentiles[:, np.logical_and(changemap <= 100, changemap > 40)], axis = (1))


    plt.figure(figsize=(15,15))
    fig, axs = plt.subplots(ncols=5, nrows = 2, figsize = (20, 15), sharey = True)
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss18, color = 'red', ax = axs[0, 0])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss18, color = 'red', label = 'Loss 2018', ax = axs[0, 0])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss19, color = 'red', ax = axs[0, 1])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss19, color = 'red', label = 'Loss 2019', ax = axs[0, 1])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss20, color = 'red', ax = axs[0, 2])
    sns.lineplot(x = (dates / 365) + 2017,y =  mean_loss20, color = 'red', label = 'Loss 2020', ax = axs[0, 2])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss21, color = 'red', ax = axs[0, 3])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss21, color = 'red', label = 'Loss 2021', ax = axs[0, 3])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss22, color = 'red', ax = axs[0, 4])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss22, color = 'red', label = 'Loss 2022', ax = axs[0, 4])

    mean_loss18 = np.mean(percentiles[:, gain2 == 1], axis = (1))
    mean_loss19 = np.mean(percentiles[:, gain2 == 2], axis = (1))
    mean_loss20 = np.mean(percentiles[:, gain2 == 3], axis = (1))
    mean_loss21 = np.mean(percentiles[:, gain2 == 4], axis = (1))
    mean_loss22 = np.mean(percentiles[:, gain2 == 5], axis = (1))
    for i in range(0, 5):
        axs[1, i].set_title(f"{np.around(befores[i] * 100, 2)}% -> {np.around(afters[i] * 100, 2)}%")
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss18, color = 'purple', ax = axs[1, 0])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss18, color = 'purple', label = 'Gain 2018', ax = axs[1, 0])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss19, color = 'purple', ax = axs[1, 1])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss19, color = 'purple', label = 'Gain 2019', ax = axs[1, 1])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss20, color = 'purple', ax = axs[1, 2])
    sns.lineplot(x = (dates / 365) + 2017,y =  mean_loss20, color = 'purple', label = 'Gain 2020', ax = axs[1, 2])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss21, color = 'purple', ax = axs[1, 3])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss21, color = 'purple', label = 'Gain 2021', ax = axs[1, 3])
    sns.scatterplot(x = (dates / 365) + 2017, y = mean_loss22, color = 'purple', ax = axs[1, 4])
    sns.lineplot(x = (dates / 365) + 2017, y = mean_loss22, color = 'purple', label = f'Gain 2022', ax = axs[1, 4])
    plt.savefig(name)
    plt.close()