period_time_list = [[1880, 1914], [1950, 1973], [1987, 2010]]
label_list = ["1", "2", "3"]

fig_2 = EvT.plot_model_posterior(
    indices=mods,  #mods, #mods, #relevant_models, 
    plot_type="MAP",
    y_axis_labels=[  #"AR(1)", 
        "M(5+)", "M(6)", "M(6+)", "M(7)", "M(7+)"
    ],  #relevant_models],
    log_format=False,
    aspect='auto',
    show_MAP_CPs=False,
    start_plot=1880,
    stop_plot=2010,
    custom_colors=["green"],  #custom_colors_models, 
    ax=ax_array[1],
    xlab=None,
    ylab=None,
    period_time_list=period_time_list,
    label_list=label_list,
    number_offset=0.75,
    number_fontsize=20,
    period_line_thickness=4.0,
    xlab_fontsize=14,
    ylab_fontsize=14,
    ylabel_coords=ylabel_coords,
    xticks_fontsize=14,
    yticks_fontsize=14,
    window_len=12 * 8)  #MAP variance 2 det: windowlen = 125
#MAP variance 1 trace: window_len = 12*8

if plot_3:
EvT.plot_model_posterior(
    indices=mod,  #mods, #mods, #relevant_models, 
    plot_type="trace",  #"MAPVariance1_trace",
    #y_axis_labels = [str(e) for e in all_models],#[#"AR(1)",
    #"M(5+)", "M(6)",
    # "M(6+)",
    # "M(7)", "M(7+)"],#relevant_models],
    time_range=time_range,
    y_axis_labels=[],
    log_format=False,
    aspect='auto',
    show_MAP_CPs=False,
    #start_plot = 2002.75, stop_plot = 2003.75,
    custom_colors=["blue", "orange"],  # ["orange"], #custom_colors_models, 
    ax=ax_array[1],  #ax_array[1], #None, #ax_array[1], 
    xlab=None,  #ylab = None, #trace",period_time_list = None,  
    number_offset=1.0,  #datetime.timedelta(days = 1),#0.75,
    number_fontsize=20,
    period_line_thickness=7.0,
    xlab_fontsize=14,
    ylab_fontsize=14,
    xticks_fontsize=14,
    yticks_fontsize=14,
    ylabel_coords=ylabel_coords,
    #ylab = None, #"Model posterior max",
    #period_time_list = [
    #   [datetime.datetime(year = 2003, month = 2, day = 17, hour = 0),
    #   datetime.datetime(year = 2003, month = 2, day = 18, hour = 0)]],
    #label_list = [["1"]],
    #window_len = int(12*7*1),
    period_time_list=
    None,  #[[datetime.datetime(year = 2003, month = 2, day = 17, hour = 0), 
    #datetime.datetime(year = 2003, month = 2, day = 18, hour = 0)]],
    label_list=None,  #[["1"]],
    SGV=True,
    log_det=True,
    all_dates=all_dates,
    true_CPs=true_CPs)
                                  additional_legend_colors = ["blue"],
                                  CP_exclude_indices = [7], #just obscures view
                                  custom_colors = custom_colors_models,
                                  custom_linestyles =custom_linestyles, 
                                  ax = ax_array[-1], figure = fig, space_to_colorbar = 0.275,
                                  orientation = 'horizontal',
                                  xlab=None, colorbar_location = "bottom",
                                  ylabel_coords = ylabel_coords,
                                  colorbar_ticks_num = 1)

if one_model_posterior_plot:
#custom_colors = ['purple', 'orange', 'red', 'green']
    fig_3 = EvT.plot_model_posterior(indices= [1,2,5,6],#relevant_models.append(30), 
                                     plot_type = "trace",
                                     y_axis_labels = ["mod1", "mod2", "mod3"],
                                     log_format=False, aspect = 'auto',
                                     show_MAP_CPs = False,
                                     custom_colors = custom_colors_models, 
                                     ax = ax_array[2], xlab = None,
                                     ylabel_coords = ylabel_coords)
    
#    if one_model_posterior_plot:
##custom_colors = ['purple', 'orange', 'red', 'green']
#    fig_3 = EvT.plot_model_posterior(indices=relevant_models, 
#                                     plot_type = "MAP",
#                                     y_axis_labels = ["mod1", "mod2", "mod3"],
#                                     log_format=False, aspect = 'auto',
#                                     show_MAP_CPs = False,
#                                     custom_colors = custom_colors_models, 
#                                     ax = None, xlab = None)
else: 
    for ind, mod in zip(range(0, len(relevant_models)), relevant_models):
            format="pdf", dpi=800)
fig.savefig(os.path.join(baseline_working_directory, "Output", "ICML18_Figure5_Nile.png"),
            format="png", dpi=800)

# Check that the figure has indeed been generated and report
if os.path.isfile(os.path.join(baseline_working_directory, "Output", "ICML18_Figure5_Nile.pdf")):
    print("Figure 5 can be found in the Output directory")

"""STEP 4: Generate additional figures, if requested"""

if save_extra_figures:

    # Plot the prediction error and variance
    fig_pe, ax_pe = plt.subplots()
    EvT.plot_prediction_error(river_height.reshape(T, 1, 1), indices=[0],
                              show_var=True, show_MAP_CPs=True,
                              up_to=250, ax=ax_pe)
    fig_pe.savefig(os.path.join(baseline_working_directory, "Output", "ICML18_ExtraFigure_Nile_PredError.pdf"),
                   format="pdf", dpi=800)
    if os.path.isfile(os.path.join(baseline_working_directory, "Output", "ICML18_ExtraFigure_Nile_PredError.pdf")):
        print("Extra plot of the prediction error can be found in the Output directory")

    # Plot the model posterior
    fig_mp, ax_mp = plt.subplots()
    EvT.plot_model_posterior(indices=[0, 1, 2], log_format=False, up_to=150,
                             plot_type="MAPVariance1_det", show_MAP_CPs=True, ax=ax_mp)
    fig_mp.savefig(os.path.join(baseline_working_directory, "Output", "ICML18_ExtraFigure_Nile_ModelPosterior.pdf"),
                   format="pdf", dpi=800)
    if os.path.isfile(os.path.join(baseline_working_directory, "Output", "ICML18_ExtraFigure_Nile_ModelPosterior.pdf")):
        print("Extra plot of the model posterior can be found in the Output directory")