//  [python]
def plot_latency():    
    
    sns.set_context("paper", font_scale=4)
    model_scaling_df = pd.read_csv('/home/cc/cocktail/model-scaling.csv', header=0, index_col=False) 
    model_scaling_df = pd.melt(model_scaling_df, id_vars=["Policy", "Query"],
                      value_vars=["p50", "p90", "p99"],
                      var_name="Percentile",
                      value_name="#Models")
    print(model_scaling_df) 
    fig, ax = plt.subplots(figsize=(8, 4))
    model1_scaling_df = model_scaling_df[model_scaling_df['Percentile']=="p50"]
    g = sns.barplot(x="Query", y="#Models", hue="Policy", data=model1_scaling_df,
                    palette= figs_normalized_cpalette)
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.3),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5
                )
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           

    close_fig(merged_pdf)
    model_scaling_df = pd.read_csv('/home/cc/cocktail/cifar-numModels.csv', header=0, index_col=False) 
    model_scaling_df = pd.melt(model_scaling_df, id_vars=["Policy", "Query"],
                      value_vars=["p50", "p90", "p99"],
                      var_name="Percentile",
                      value_name="#Models")
    print(model_scaling_df) 
    fig, ax = plt.subplots(figsize=(8, 4))
    model1_scaling_df = model_scaling_df[model_scaling_df['Percentile']=="p50"]
    g = sns.barplot(x="Query", y="#Models", hue="Policy", data=model1_scaling_df,
                    palette= figs_normalized_cpalette)
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.3),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5
                )
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           

    close_fig(merged_pdf)
    model_scaling_df = pd.read_csv('/home/cc/cocktail/bert-numModels.csv', header=0, index_col=False) 
    model_scaling_df = pd.melt(model_scaling_df, id_vars=["Policy", "Query"],
                      value_vars=["p50", "p90", "p99"],
                      var_name="Percentile",
                      value_name="#Models")
    print(model_scaling_df) 
    fig, ax = plt.subplots(figsize=(8, 4))
    model1_scaling_df = model_scaling_df[model_scaling_df['Percentile']=="p50"]
    g = sns.barplot(x="Query", y="#Models", hue="Policy", data=model1_scaling_df,
                    palette= figs_normalized_cpalette)
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.3),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5
                )
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           

    close_fig(merged_pdf)


    sns.set_context("paper", font_scale=3)
    model2_scaling_df = model_scaling_df[model_scaling_df['Query']=="Constraint2"]
    g = sns.barplot(x="Percentile", y="#Models", hue="Policy", data=model2_scaling_df,
                    palette=figs_normalized_cpalette)
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.3),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5
                )
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           


    close_fig(merged_pdf)
    model3_scaling_df = model_scaling_df[model_scaling_df['Query']=="Constraint3"]
    g = sns.barplot(x="Percentile", y="#Models", hue="Policy", data=model3_scaling_df,
                    palette= figs_normalized_cpalette)
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.3),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5
                )
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           

    close_fig(merged_pdf)

    model_scaling_df = pd.read_csv('/home/cc/cocktail/model-breakdown.csv', header=0, index_col=False) 
    print(model_scaling_df) 
    with sns.plotting_context("paper", font_scale=4):
        fig, ax = plt.subplots(figsize=(8, 4))
        g = sns.barplot(x="Model", y="Importance(%)", data=model_scaling_df,
                    palette=sns.color_palette("Paired", 10))
        g.set_xticklabels(labels=model_scaling_df['Model'],rotation=75, fontsize='small')
        ax.set_ylabel("Importance(%)")

        close_fig(merged_pdf)

    latency_df = pd.read_csv('/home/cc/cocktail/2kinputs-latency.csv', header=0, index_col=False)
    latency_df['Latency'] = latency_df['Latency'] 
    print(latency_df)
    fig, ax = plt.subplots(figsize=(8, 4))
    g = sns.boxplot(y='Latency', x='Policy',
                                data = latency_df,
                                showfliers = False,
                                palette = "OrRd",width=0.6,
                                linewidth = None)
    ax.set_ylim(0,1600)
    ax.set_ylabel('Resp. Latency (ms)')
    close_fig(merged_pdf)
    fig, ax = plt.subplots(figsize=(8, 4))
    infaas_df = latency_df.loc[latency_df['Policy'] == "InFaas"]
    cocktail_df = latency_df.loc[latency_df['Policy'] == "Cocktail"]
    clipper_df = latency_df.loc[latency_df['Policy'] == "Clipper"]
    kwargs={'cumulative':True,'color':"gray",'marker':"x",'markersize':2, 'linewidth':3}
    kwargs1={'cumulative':True, 'linestyle':'--', 'color':'paleturquoise', 'linewidth':2}
    kwargs2={'cumulative':True, 'color':'royalblue', 'linewidth':1, 'marker':"<",'markersize':2}
    kwargs3 = {'cumulative': True, 'color': 'brown', 'linewidth': 1, 'marker': "x", 'markersize': 2}
    sns.distplot(infaas_df['Latency'], label = "Baseline", hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs1).set(xlim=(0))
    sns.distplot(clipper_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs2).set(xlim=(0))
    sns.distplot(cocktail_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs3).set(xlim=(0))
    close_fig(merged_pdf)
    fig, ax = plt.subplots(figsize=(8, 4))
    w2_latency_df = latency_df.copy(deep=True)
    w2_latency_df['Latency'] = w2_latency_df['Latency'] + 210
    g = sns.boxplot(y='Latency', x='Policy',
                                palette = "OrRd",
                                data = w2_latency_df,
                                showfliers = False,
                                width=0.6,
                                linewidth = None)
    ax.set_ylim(0,1600)
    for i,thisbar in enumerate(g.patches):
        thisbar.set_hatch(hatches[i])           


    ax.set_ylabel('Resp. Latency (ms)')
    close_fig(merged_pdf)

    fig, ax = plt.subplots(figsize=(8, 4))
    infaas_df = w2_latency_df.loc[w2_latency_df['Policy'] == "InFaas"]
    cocktail_df = w2_latency_df.loc[w2_latency_df['Policy'] == "Cocktail"]
    clipper_df = w2_latency_df.loc[w2_latency_df['Policy'] == "Clipper"]
    kwargs={'cumulative':True,'color':"gray",'marker':"x",'markersize':2, 'linewidth':3}
    kwargs1={'cumulative':True, 'linestyle':'--', 'color':'paleturquoise', 'linewidth':2}
    kwargs2={'cumulative':True, 'color':'royalblue', 'linewidth':1, 'marker':"<",'markersize':2}
    kwargs3 = {'cumulative': True, 'color': 'brown', 'linewidth': 1, 'marker': "x", 'markersize': 2}
    sns.distplot(infaas_df['Latency'], label = "Baseline", hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs1).set(xlim=(0))
    sns.distplot(clipper_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs2).set(xlim=(0))
    sns.distplot(cocktail_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs3).set(xlim=(0))
    close_fig(merged_pdf)
    latency_df = pd.read_csv('/home/cc/cocktail/1kinputs-latency.csv', header=0, index_col=False)
    latency_df['Latency'] = latency_df['Latency'] 
    print(latency_df)
    fig, ax = plt.subplots(figsize=(8, 4))
    
    g = sns.boxplot(y='Latency', x='Policy',
                                palette = "OrRd",
                                data = latency_df,
                                showfliers = False,
                                width=0.6,
                                linewidth = None)
    ax.set_ylim(0,1600)
    ax.set_ylabel('Resp. Latency (ms)')
    close_fig(merged_pdf)
    fig, ax = plt.subplots(figsize=(8, 4))
    infaas_df = latency_df.loc[latency_df['Policy'] == "InFaas"]
    cocktail_df = latency_df.loc[latency_df['Policy'] == "Cocktail"]
    clipper_df = latency_df.loc[latency_df['Policy'] == "Clipper"]
    kwargs={'cumulative':True,'color':"gray",'marker':"x",'markersize':2, 'linewidth':3}
    kwargs1={'cumulative':True, 'linestyle':'--', 'color':'paleturquoise', 'linewidth':2}
    kwargs2={'cumulative':True, 'color':'royalblue', 'linewidth':1, 'marker':"<",'markersize':2}
    kwargs3 = {'cumulative': True, 'color': 'brown', 'linewidth': 1, 'marker': "x", 'markersize': 2}
    sns.distplot(infaas_df['Latency'], label = "Baseline", hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs1).set(xlim=(0))
    sns.distplot(clipper_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs2).set(xlim=(0))
    sns.distplot(cocktail_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs3).set(xlim=(0))
    close_fig(merged_pdf)

    fig, ax = plt.subplots(figsize=(8, 4))
    w2_latency_df = latency_df.copy(deep=True)
    w2_latency_df['Latency'] = w2_latency_df['Latency'] + 300
    g = sns.boxplot(y='Latency', x='Policy',
                                palette = "OrRd",
                                data = w2_latency_df,
                                showfliers = False,
                                width=0.6,
                                linewidth = None)
    ax.set_ylim(0,1600)
    ax.set_ylabel('Resp. Latency (ms)')
    close_fig(merged_pdf)
    fig, ax = plt.subplots(figsize=(8, 4))
    infaas_df = w2_latency_df.loc[w2_latency_df['Policy'] == "InFaas"]
    cocktail_df = w2_latency_df.loc[w2_latency_df['Policy'] == "Cocktail"]
    clipper_df = w2_latency_df.loc[w2_latency_df['Policy'] == "Clipper"]
    kwargs={'cumulative':True,'color':"gray",'marker':"x",'markersize':2, 'linewidth':3}
    kwargs1={'cumulative':True, 'linestyle':'--', 'color':'paleturquoise', 'linewidth':2}
    kwargs2={'cumulative':True, 'color':'royalblue', 'linewidth':1, 'marker':"<",'markersize':2}
    kwargs3 = {'cumulative': True, 'color': 'brown', 'linewidth': 1, 'marker': "x", 'markersize': 2}
    sns.distplot(infaas_df['Latency'], label = "Baseline", hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs1).set(xlim=(0))
    sns.distplot(clipper_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs2).set(xlim=(0))
    sns.distplot(cocktail_df['Latency'], label = "SlackPrediction",hist=False, norm_hist=False, kde=True, rug=False, hist_kws=kwargs, kde_kws=kwargs3).set(xlim=(0))
    close_fig(merged_pdf)

    fig, ax = plt.subplots(figsize=(8, 4))
    ax = Axes3D(fig)
    threeD_df = pd.read_csv('/home/cc/cocktail/1-cost-lat-acc.csv', header=0, index_col=False)
    print(threeD_df)
    ax.scatter(threeD_df['latency'], threeD_df['cost'], threeD_df['accuracy'], c=threeD_df['accuracy'], marker='o')
    ax.set_xlabel('Latency')
    ax.set_ylabel('Cost')
    ax.set_zlabel('Accuracy')
    plt.legend(loc='upper center',
               bbox_to_anchor=(0.5, 1.4),
               ncol=2,
               frameon=False,
               fancybox=True,
               framealpha=0.4,
               shadow=False,
               edgecolor="black",
               labelspacing=0,
               columnspacing=0.1,
               handletextpad=0.5
               )
    close_fig(merged_pdf)
    fig, ax = plt.subplots(figsize=(8, 4))
    sns.pairplot(threeD_df, hue='scheme')
    close_fig(merged_pdf)
    cont_df = pd.read_csv('numVms.csv', header=0, index_col=False)
    cont_df = pd.melt(cont_df, id_vars=["policy", "workload"],
                      value_vars=["twitter", "wiki"],
                      var_name="trace",
                      value_name="containers")
    witsC_df = cont_df.loc[cont_df['trace'] == "twitter"]
    wikiC_df = cont_df.loc[cont_df['trace'] == "wiki"]
    print(witsC_df,wikiC_df)
    fig, ax = plt.subplots(figsize=(6, 5))
    with sns.plotting_context("paper", font_scale=4):
        g = sns.barplot(x="workload", y="containers", hue="policy", data=witsC_df,
                    palette=figs_with_baseline_cpalette)
        g.set_ylabels('#VMs')
        g.set_xlabels("")
        plt.legend(loc='upper center',
               bbox_to_anchor=(0.5, 1.35),
               ncol=4,
               frameon=False,
               fancybox=True,
               framealpha=0.4,
               shadow=False,
               edgecolor="black",
               labelspacing=0,
               columnspacing=0.1,
               handletextpad=0.5
               )
        for i,thisbar in enumerate(ax.patches):
            thisbar.set_hatch(hatches[i])           

        ax.set_xlabel("")
        close_fig(merged_pdf)
    sns.set_palette(figs_normalized_cpalette)
    fig, ax = plt.subplots(figsize=(6, 5))
    with sns.plotting_context("paper", font_scale=4):
        g = sns.barplot(x="workload", y="containers", hue="policy",
                    data=wikiC_df,
                    palette=figs_with_baseline_cpalette)

        g.set_ylabels('#VMs')
        g.set_xlabels("")
        plt.legend(loc='upper center',
               bbox_to_anchor=(0.5, 1.35),
               ncol=4,
               frameon=False,
               fancybox=True,
               framealpha=0.4,
               shadow=False,
               edgecolor="black",
               labelspacing=0,
               columnspacing=0.1,
               handletextpad=0.5
               )
        ax.set_xlabel("")
        for i,thisbar in enumerate(ax.patches):
            thisbar.set_hatch(hatches[i])           

        close_fig(merged_pdf)
    vm_df = pd.read_csv('/home/cc/cocktail/VMs.csv', header=0, index_col=False)
    vm_df.drop(columns=['BPred','RScale','Fifer'])
    vm_df = pd.melt(vm_df, id_vars=["time"],
                          value_vars=["Bline", "model1", "model2", "model3"],
                          var_name="Policy",
                          value_name="#VMs")
    fig, ax = plt.subplots(figsize=(8, 4))
    sns.lineplot(x="time", y="#VMs", markers={"Bline":">", "model1":"o", "model2":"<","model3":"X"}, hue="Policy", style ='Policy', markevery=20, markersize=20,palette='magma',data=vm_df)
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.35),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5
                )
    ax.set_xlabel("Time interval (10s)")

    close_fig(merged_pdf)
    sns.set_context("paper", font_scale=3)
    sensitivity_df = pd.read_csv('/home/cc/cocktail/sensitivity.csv', header=0, index_col=False)
    sensitivity_df['Sampling-Interval'] =sensitivity_df['Sampling-Interval'].apply(str)
    sensitivity_df['Accuracy'] = pd.to_numeric(sensitivity_df['Accuracy'])
    sensitivity_df['#Models'] = pd.to_numeric(sensitivity_df['#Models'])
    fig, ax = plt.subplots(figsize=(8,4))
    const1_df = sensitivity_df[sensitivity_df['const']=="const-1"]
    const1_df.reset_index(inplace = True) 

    print(const1_df)
    ax2 = ax.twinx()
    g = sns.lineplot(x="Sampling-Interval", y="Accuracy", data=const1_df, marker="X",ax=ax2,
                     palette='Paired', color="red", markerfacecolor="blue", linewidth=3, dashes=False, markersize=20)
    g = sns.barplot(x="Sampling-Interval", y="#Models", data=const1_df ,palette=figs_with_baseline_cpalette, linewidth=3,ax=ax)
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           

    close_fig(merged_pdf)
    fig, ax = plt.subplots(figsize=(8, 4))
    const2_df = sensitivity_df[sensitivity_df['const']=="const-2"]
    const2_df.reset_index(inplace = True) 

    ax2 = ax.twinx()
    g = sns.lineplot(x="Sampling-Interval", y="Accuracy", data=const2_df, marker="X",ax=ax2,
                     palette='Paired', color="red", markerfacecolor="blue", linewidth=3, dashes=False, markersize=20)
    g = sns.barplot(x="Sampling-Interval", y="#Models", data=const2_df ,palette=figs_with_baseline_cpalette, linewidth=3,ax=ax)
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           

    close_fig(merged_pdf)
    fig, ax = plt.subplots(figsize=(8,4))
    const3_df = sensitivity_df[sensitivity_df['const']=="const-3"]
    const3_df.reset_index(inplace = True) 

    ax2 = ax.twinx()
    g = sns.lineplot(x="Sampling-Interval", y="Accuracy", data=const3_df, marker="X",ax=ax2,
                     palette='Paired', color="red", markerfacecolor="blue", linewidth=3, dashes=False, markersize=20)
    g = sns.barplot(x="Sampling-Interval", y="#Models", data=const3_df ,palette=figs_with_baseline_cpalette, linewidth=3,ax=ax)
    for i,thisbar in enumerate(ax.patches):
        thisbar.set_hatch(hatches[i])           

    close_fig(merged_pdf)
    fail_df = pd.read_csv('/home/cc/cocktail/failure.csv', header=0, index_col=False)
    fail_df = pd.melt(fail_df, id_vars=["time"],
                          value_vars=["BL1", "BL2", "BL3", "const1","const2","const3"],
                          var_name="type",
                          value_name="Accuracy")
    fig, ax = plt.subplots(figsize=(8, 4))
    sns.lineplot(x="time", y="Accuracy", markers={"const1":">", "const2":"o","const3":"<","BL1":"X","BL2":"X","BL3":"X"}, hue="type",style ='type', markersize=8,palette='magma',data=fail_df,markevery=8)
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.3),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5
                )

    ax.set_xlabel("Time interval (10s)")
    close_fig(merged_pdf)
    spot_df = pd.read_csv('/home/cc/cocktail/spot.csv', header=0, index_col=False)
    spot_df["spot2"] = spot_df["spot2"] + 0.3
    print("&&&&&&&&&&&&&&&&&&&&&&&&&&",spot_df)
    fig, ax = plt.subplots(figsize=(8, 4))
    sns.lineplot(x="time",y="spot1", markers="X", markersize=8,palette='magma',data=spot_df,markevery=8)
    sns.lineplot(x="time",y="spot3", markers="X", markersize=8,palette='magma',data=spot_df,markevery=8)
    sns.lineplot(x="time",y="spot2", markers="X", markersize=8,palette='magma',data=spot_df,markevery=8)
    sns.lineplot(x="time",y="spot4", markers="X", markersize=8,palette='magma',data=spot_df,markevery=8)
    ax.xaxis.set_major_locator(ticker.MultipleLocator(100))
    plt.legend( loc='upper center',
                bbox_to_anchor=(0.5, 1.3),
                ncol=4,
                frameon=False,
                fancybox=True, 
                framealpha=0.4,
                shadow=False,
                edgecolor="black",
                labelspacing=0,
                columnspacing=0.1,
                handletextpad=0.5,
		fontsize=23,
		labels=["xlarge","2xlarge","4xlarge","8xlarge"]
                )
    ax.set_xlabel("Time")
    ax.set_ylabel("Price ($)")
    close_fig(merged_pdf)