jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def draw_stateful(df2, resource):
    df = df2[df2["Resource"] == resource]

    avgs = df.groupby(['Limit']).mean().reset_index()
    avgs["Benchmark"] = "Mean"
    df = pd.concat([df,avgs], axis=0, ignore_index=True, sort=False)

    # fig, ax = plt.subplots(figsize=(15,3))
    set_style()
    ax = sns.catplot(x="Benchmark", y="Execution Time Improvement", hue="Limit", data=df, kind="bar", 
                    palette=("Purples"), height=6, aspect=1.2, legend=False)
    ax.set_xticklabels(rotation=90)
    ax.fig.tight_layout()

    plt.legend(loc=("upper center"),
            bbox_to_anchor=(.50, 1.40),
            ncol=5,
            prop={'size': 15},
            title="Adaptation Limit",
    )
    ax.axes.flatten()[0].set_ylim(df["Execution Time Improvement"].min()-0.02, df["Execution Time Improvement"].max()+0.02)
    ax.axes.flatten()[0].set_ylabel('Speedup \nover Shared', fontsize = 20)
    axes = ax.axes.flatten()
    for ax in axes:
        ax.set_xlabel("")
        for i, bar in enumerate(ax.patches):
            bar.set_edgecolor('black')

    plt.savefig("fig-adaptive-{}.pdf".format(resource), bbox_inches='tight')
//  [python]
def plot(input):
    df = pd.read_csv(input)
    df = df[['drive', 'frame_idx', 't_outlier', 't_polylidar_all', 't_polyfilter']]
    df_melt = pd.melt(df, id_vars=['drive', 'frame_idx'], var_name=['Group'], value_vars=[
                      't_outlier', 't_polylidar_all', 't_polyfilter'], value_name='Execution Time (ms)')
    facet_kwargs = dict(gridspec_kws=dict(hspace=.05))
    g = sns.factorplot(x="Group", y="Execution Time (ms)", col='drive', data=df_melt, col_wrap=4, kind='boxen')
    g.set(ylim=(0, 20))
    # ax = sns.boxplot(x="Group", y="Execution Time", data=df_melt)
    plt.subplots_adjust(hspace=0.2, wspace=0.05)
    plt.show()
//  [python]
def plot(input):
    df = pd.read_csv(input)
    df = df[['drive', 'frame_idx', 't_outlier', 't_polylidar_all', 't_polyfilter']]
    df_melt = pd.melt(df, id_vars=['drive', 'frame_idx'], var_name=['Group'], value_vars=[
                      't_outlier', 't_polylidar_all', 't_polyfilter'], value_name='Execution Time (ms)')
    facet_kwargs = dict(gridspec_kws=dict(hspace=.05))
    g = sns.catplot(x="Group", y="Execution Time (ms)", col='drive', data=df_melt, col_wrap=4, kind='boxen')
    g.set(ylim=(0, 20))
    # ax = sns.boxplot(x="Group", y="Execution Time", data=df_melt)
    plt.subplots_adjust(hspace=0.2, wspace=0.05)
    plt.show()
//  [python]
def draw_stateless(df2, resource):
    df = df2[df2["Resource"] == resource]
    avgs = df.groupby(['Limit','Mult']).mean().reset_index()
    avgs["Benchmark"] = "Mean"
    df = pd.concat([df,avgs], axis=0, ignore_index=True, sort=False)

    set_style()
    g = sns.FacetGrid(df, col="Mult", hue="Limit", palette=("Purples"), height=6, aspect=0.9)
    g.map(sns.barplot, "Benchmark", "Execution Time Improvement")
    g.add_legend(title="Adaptation Limit", loc=("upper center"), bbox_to_anchor=(-.5, 1.49), ncol=5, prop={'size': 20})
    g.set_xticklabels(rotation=90)
    g.fig.tight_layout()
    g.axes.flatten()[0].set_ylim(df["Execution Time Improvement"].min()-0.02, df["Execution Time Improvement"].max()+0.02)
    g.axes.flatten()[0].set_ylabel('Speedup \nover Shared', fontsize = 20)

    axes = g.axes.flatten()
    for ax in axes:
        ax.set_xlabel("")
        for i, bar in enumerate(ax.patches):
            bar.set_edgecolor('black')

    plt.savefig("fig-adaptive-{}.pdf".format(resource), bbox_inches='tight')
//  [python]
def draw_stateless(df2, resource):
    df = df2[df2["Resource"] == resource]
    avgs = df.groupby(['Limit','Mult']).mean().reset_index()
    avgs["Benchmark"] = "Mean"
    df = pd.concat([df,avgs], axis=0, ignore_index=True, sort=False)

    set_style()
    ax = sns.catplot(x="Benchmark", y="Execution Time Improvement", hue="Limit", col="Mult", data=df, kind="bar", 
                    palette=("Purples"),  height=6, aspect=0.9, legend=False)
    ax.set_xticklabels(rotation=90)
    ax.fig.tight_layout()
    plt.legend(loc=("upper center"),
            bbox_to_anchor=(-.5, 1.49),
            ncol=5,
            prop={'size': 20},
            title="Adaptation Limit",
    
    )
    ax.axes.flatten()[0].set_ylim(df["Execution Time Improvement"].min()-0.02, df["Execution Time Improvement"].max()+0.02)
    ax.axes.flatten()[0].set_ylabel('Speedup \nover Shared', fontsize = 20)

    axes = ax.axes.flatten()
    for ax in axes:
        ax.set_xlabel("")
        for i, bar in enumerate(ax.patches):
            bar.set_edgecolor('black')

    plt.savefig("fig-adaptive-{}.pdf".format(resource), bbox_inches='tight')
//  [python]
def describe_wa(wa_csv):
    df = pd.read_csv(wa_csv)
    logger.info(f"\n{df.head()}")
    d = df.groupby("Model").describe()
    logger.info(d)
    # violin plot
    mean_order = (
        df.groupby("Model")["value"]
        .mean()
        .reset_index()
        .sort_values("value", ascending=False)["Model"]
    )
    logger.info(mean_order)
    ax = sns.violinplot(
        x="Model", y="value", data=df, order=mean_order, palette=palette
    )
    ax.set(xlabel=f"Model/Method", ylabel="Weighted average of top 10 batet scores")
    ax.set_xticklabels(rotation=45, ha="right")
    # ax.set_xscale("log")
    plt.savefig(f"{output2}/images/wa-violin-plot.png", dpi=1000)
//  [python]
def describe_wa(wa_csv):
    df = pd.read_csv(wa_csv)
    logger.info(f"\n{df.head()}")
    d = df.groupby("Model").describe()
    logger.info(d)
    # violin plot
    mean_order = (
        df.groupby("Model")["value"]
        .mean()
        .reset_index()
        .sort_values("value", ascending=False)["Model"]
    )
    logger.info(mean_order)
    ax = sns.catplot(
        x="Model", y="value", data=df, kind="violin", order=mean_order, palette=palette
    )
    ax.set(xlabel=f"Model/Method", ylabel="Weighted average of top 10 batet scores")
    ax.set_xticklabels(rotation=45, ha="right")
    # ax.set_xscale("log")
    ax.savefig(f"{output2}/images/wa-violin-plot.png", dpi=1000)
//  [python]
def plot_testability_box_whisker_plot():
    df_all = pandas.DataFrame()
    for project, paths in project_name_path_dict.items():
        df = pandas.DataFrame()
        df_before = pd.read_csv(
            paths[0],
            index_col=False
        )
        df_after = pd.read_csv(
            paths[1],
            index_col=False
        )

        df['Project'] = [project] * (len(df_before) + len(df_after))
        df['Stage'] = [*['Before refactoring'] * len(df_before), *['After refactoring'] * len(df_after)]

        df = pd.concat([df, pd.concat([df_before, df_after], ignore_index=True)], axis=1, join='inner')
        df.drop(columns=['Class', 'PredictedTestability'], inplace=True)
        # df.drop(columns=['Class', ], inplace=True)
        df_all = pd.concat([df_all, df], ignore_index=True)

    print(df_all)

    df3 = df_all.melt(id_vars=['Project', 'Stage'], var_name='Metric', value_name='Value')
    print(df3)
    # quit()
    g = sns.factorplot(data=df3,
                    # x='Metric', y='Value', hue='Stage', col='Project',
                    x='Project', y='Value', hue='Stage', col='Metric',
                    col_wrap=1,
                    kind='box',
                    sharex=False, sharey=False, margin_titles=True,
                    size=1.75, aspect=1.25, orient='v',
                    legend_out=False, legend=True, dodge=True)

    g2 = sns.factorplot(data=df3,
                     # x='Metric', y='Value', hue='Stage', col='Project',
                     x='Project', y='Value', hue='Stage', col='Metric',
                     col_wrap=1,
                     kind='point',
                     sharex=False, sharey=False, margin_titles=True,
                     size=2.5, aspect=0.95, orient='v',
                     legend_out=False, legend=True, dodge=True,
                     # axes=g.axes
                     palette=reversed(sns.color_palette('tab10', n_colors=2)),
                     markers=['o', '*', 'X'] * 2, linestyles=['dashed', 'dotted', '-.'] * 2
                     )
    # g.set(yscale="log")
    g.despine(left=True)
    g2.despine(left=True)
    # g.axes[19].legend(loc='upper center')
    # g2.axes[19].legend(loc='upper center')
    plt.tight_layout()
    plt.show()
//  [python]
def plot_testability_box_whisker_plot():
    df_all = pandas.DataFrame()
    for project, paths in project_name_path_dict.items():
        df = pandas.DataFrame()
        df_before = pd.read_csv(
            paths[0],
            index_col=False
        )
        df_after = pd.read_csv(
            paths[1],
            index_col=False
        )

        df['Project'] = [project] * (len(df_before) + len(df_after))
        df['Stage'] = [*['Before refactoring'] * len(df_before), *['After refactoring'] * len(df_after)]

        df = pd.concat([df, pd.concat([df_before, df_after], ignore_index=True)], axis=1, join='inner')
        df.drop(columns=['Class', 'PredictedTestability'], inplace=True)
        # df.drop(columns=['Class', ], inplace=True)
        df_all = pd.concat([df_all, df], ignore_index=True)

    print(df_all)

    df3 = df_all.melt(id_vars=['Project', 'Stage'], var_name='Metric', value_name='Value')
    print(df3)
    # quit()
    g = sns.catplot(data=df3,
                    # x='Metric', y='Value', hue='Stage', col='Project',
                    x='Project', y='Value', hue='Stage', col='Metric',
                    col_wrap=1,
                    kind='box',
                    sharex=False, sharey=False, margin_titles=True,
                    height=1.75, aspect=1.25, orient='v',
                    legend_out=False, legend=True, dodge=True)

    g2 = sns.catplot(data=df3,
                     # x='Metric', y='Value', hue='Stage', col='Project',
                     x='Project', y='Value', hue='Stage', col='Metric',
                     col_wrap=1,
                     kind='point',
                     sharex=False, sharey=False, margin_titles=True,
                     height=2.5, aspect=0.95, orient='v',
                     legend_out=False, legend=True, dodge=True,
                     # axes=g.axes
                     palette=reversed(sns.color_palette('tab10', n_colors=2)),
                     markers=['o', '*', 'X'] * 2, linestyles=['dashed', 'dotted', '-.'] * 2
                     )
    # g.set(yscale="log")
    g.despine(left=True)
    g2.despine(left=True)
    # g.axes[19].legend(loc='upper center')
    # g2.axes[19].legend(loc='upper center')
    plt.tight_layout()
    plt.show()
//  [python]
def metaGenes(self, **kwargs):
        if self.symbolDf is None: self.ensembl2symbol()
        if self.metaGeneDf is None: self.readCsv(readType = 'meta-gene')
        df = self.metaGeneDf
        df = df.iloc[:, 0:2]
        self.metaGenesBoxDf = pd.DataFrame(columns = ['Expression', 'Cluster', 'Metagene'])
        for x in df['Network cluster'].unique():
            for i, cluster in enumerate(self.sortedClusterList):
                values = (self.symbolDf[cluster].filter(items = list(df[df['Network cluster'] == x]['Gene Symbol']), axis = 0).mean(axis = 1).values)
                tempDf = pd.DataFrame({'Expression': values, 'Cluster':[i+1 for c in range(len(values))], 'Metagene':[x for c in range(len(values))]})
                self.metaGenesBoxDf = pd.concat([self.metaGenesBoxDf, tempDf])
        ax = sns.boxplot(data = self.metaGenesBoxDf, x = 'Cluster', y = 'Expression', hue = 'Metagene', **kwargs)
//  [python]
def metaGenes(self, **kwargs):
        if self.symbolDf is None: self.ensembl2symbol()
        if self.metaGeneDf is None: self.readCsv(readType = 'meta-gene')
        df = self.metaGeneDf
        df = df.iloc[:, 0:2]
        self.metaGenesBoxDf = pd.DataFrame(columns = ['Expression', 'Cluster', 'Metagene'])
        for x in df['Network cluster'].unique():
            for i, cluster in enumerate(self.sortedClusterList):
                values = (self.symbolDf[cluster].filter(items = list(df[df['Network cluster'] == x]['Gene Symbol']), axis = 0).mean(axis = 1).values)
                tempDf = pd.DataFrame({'Expression': values, 'Cluster':[i+1 for c in range(len(values))], 'Metagene':[x for c in range(len(values))]})
                self.metaGenesBoxDf = pd.concat([self.metaGenesBoxDf, tempDf])
        ax = sns.catplot(kind = 'box', data = self.metaGenesBoxDf, x = 'Cluster', y = 'Expression', col = 'Metagene', **kwargs)
//  [python]
def boxplotExternalData(self, cols = 6):
        if self.immuneDf is None: self.readImmuneData()
        df = self.immuneDf
        for column in list(df):
            if not is_numeric_dtype(df[column]): df = df.drop([column], axis = 1)
        df['id'] = df.index.tolist()
        self.newDf = pd.melt(df, id_vars = ['id', 'Clusters'])
        g = sns.FacetGrid(data = self.newDf, col = 'variable', col_wrap = cols, sharey = False)
        g.map(sns.boxplot, 'Clusters', 'value')
//  [python]
def boxplotExternalData(self, cols = 6):
        if self.immuneDf is None: self.readImmuneData()
        df = self.immuneDf
        for column in list(df):
            if not is_numeric_dtype(df[column]): df = df.drop([column], axis = 1)
        df['id'] = df.index.tolist()
        self.newDf = pd.melt(df, id_vars = ['id', 'Clusters'])
        g = sns.catplot(data = self.newDf, kind = 'box', col = 'variable', y ='value', x = 'Clusters', col_wrap = cols, sharey = False)
//  [python]
def draw_cat_plot():
    vars = sorted(
        ["cholesterol", "gluc", "smoke", "alco", "active", "overweight"]
    )

    df_cat = pd.melt(
        df,
        id_vars=["cardio"],
        value_vars=vars,
    )

    df_cat = df_cat.value_counts().reset_index(name="total")

    g = sns.factorplot(
        data=df_cat,
        x="variable",
        y="total",
        hue="value",
        col="cardio",
        kind="bar",
        order=vars,
    )
    g.set_ylabels("total")
    g.set_xlabels("variable")
    fig = g.fig

    return fig
//  [python]
def draw_cat_plot():
    # Create DataFrame for cat plot using `pd.melt` using just the values from
    # 'cholesterol', 'gluc', 'smoke', 'alco', 'active', and 'overweight'.
    vars = sorted(
        ["cholesterol", "gluc", "smoke", "alco", "active", "overweight"]
    )

    df_cat = pd.melt(
        df,
        id_vars=["cardio"],
        value_vars=vars,
    )

    # Group and reformat the data to split it by 'cardio'. Show the counts of
    # each feature. You will have to rename one of the columns for the catplot
    # to work correctly.
    df_cat = df_cat.value_counts().reset_index(name="total")

    # Draw the catplot with 'sns.catplot()'
    fig = sns.catplot(
        data=df_cat,
        x="variable",
        y="total",
        hue="value",
        col="cardio",
        kind="bar",
        order=vars,
    )
    fig.set_ylabels("total")
    fig.set_xlabels("variable")
    fig = fig.fig

    # Do not modify the next two lines
    # fig.savefig("catplot.png") # Don't save to file
    return fig
//  [python]
cols = ["tool", "vers", "test", "jobs", "conf", "file", "start", "end", "time"]
data = pd.read_csv("data.csv", names=cols)
sns.set_theme()
plot = sns.factorplot(data=data, kind="bar", x="tool", y="time")
//  [python]
cols = ["tool", "vers", "test", "jobs", "conf", "file", "start", "end", "time"]
data = pd.read_csv("data.csv", names=cols)
sns.set_theme()
plot = sns.catplot(data=data, kind="bar", x="tool", y="time")
//  [python]
def demoRun(self, cutoffs, csvpath, clusterpath, columnname = 'Gene', **kwargs):
        #Allows the user to get an overview over the SRIQ output
        #cutoffs: dictionary of cutoff:[cluster values]
        self.sDf = pd.DataFrame({'per_var', 'cutoff','num' })
        self.uDf = pd.DataFrame(columns = ['comp 1','comp 2','cutoff', 'hue'])
        lista = list()
        
        #Fetches the information from the specified clusters
        for i, cutoff in enumerate(cutoffs):
            print(f'Run {i+1} out of {len(cutoffs)}')
            for j, clust in enumerate(cutoffs[cutoff]):
                cpath = clusterpath.split('/')
                cpath[-2] = 'dist({})'.format(cutoff)
                cpath[-1] = '{}'.format(clust)
                cpath = '/'.join(cpath)
                lista.append(cpath[-8:])
                self.readSRIQ(csvpath, cpath, columnname)
                self.calcPcaModel(demo = cpath[-8:])
                self.Umap(3,demo = cpath[-8:])
                
        #plots the information from the fetched info
        g = sns.factorplot(x= 'num', y='per_var',kind='bar', data = self.sDf, col='cutoff',col_wrap= 2, sharey = False, sharex = False, **kwargs)
        g2 = sns.relplot(x= 'comp 1', y='comp 2', data= self.uDf, style = 'hue', hue='hue', col='cutoff',col_wrap=2, sharey = False, sharex = False, **kwargs)
//  [python]
def demoRun(self, cutoffs, csvpath, clusterpath, columnname = 'Gene', **kwargs):
        #Allows the user to get an overview over the SRIQ output
        #cutoffs: dictionary of cutoff:[cluster values]
        self.sDf = pd.DataFrame({'per_var', 'cutoff','num' })
        self.uDf = pd.DataFrame(columns = ['comp 1','comp 2','cutoff', 'hue'])
        lista = list()
        
        #Fetches the information from the specified clusters
        for i, cutoff in enumerate(cutoffs):
            print(f'Run {i+1} out of {len(cutoffs)}')
            for j, clust in enumerate(cutoffs[cutoff]):
                cpath = clusterpath.split('/')
                cpath[-2] = 'dist({})'.format(cutoff)
                cpath[-1] = '{}'.format(clust)
                cpath = '/'.join(cpath)
                lista.append(cpath[-8:])
                self.readSRIQ(csvpath, cpath, columnname)
                self.calcPcaModel(demo = cpath[-8:])
                self.Umap(3,demo = cpath[-8:])
                
        #plots the information from the fetched info
        g = sns.catplot(x= 'num', y='per_var',kind='bar', data = self.sDf, col='cutoff',col_wrap= 2, sharey = False, sharex = False, **kwargs)
        g2 = sns.relplot(x= 'comp 1', y='comp 2', data= self.uDf, style = 'hue', hue='hue', col='cutoff',col_wrap=2, sharey = False, sharex = False, **kwargs)
//  [python]
def plot_eval_bar_chart(eval_record, title=''):
    performances = [eval_record[criterion] for criterion in sorted(eval_record.keys())]
    criteria = list(sorted(eval_record.keys()))
    curricula = sorted(performances[0].keys(), key=lambda x: -len(x))

    df_list = list()
    for i, criterion in enumerate(criteria):
        for j, curriculum in enumerate(curricula):
            df_list.append(
                {
                    "curriculum": curriculum,
                    "eval criterion": criterion,
                    "success rate": performances[i][curriculum]
                }
            )

    df = pd.DataFrame(df_list)
    print(df.to_string())
    ax = sns.factorplot(x="eval criterion", y="success rate", hue="curriculum", data=df,
                     height=12, kind="bar", palette="Paired", )
    plt.title(title)
    return ax
//  [python]
def plot_eval_bar_chart(eval_record, title=''):
    performances = [eval_record[criterion] for criterion in sorted(eval_record.keys())]
    criteria = list(sorted(eval_record.keys()))
    curricula = sorted(performances[0].keys(), key=lambda x: -len(x))

    df_list = list()
    for i, criterion in enumerate(criteria):
        for j, curriculum in enumerate(curricula):
            df_list.append(
                {
                    "curriculum": curriculum,
                    "eval criterion": criterion,
                    "success rate": performances[i][curriculum]
                }
            )

    df = pd.DataFrame(df_list)
    print(df.to_string())
    ax = sns.catplot(x="eval criterion", y="success rate", hue="curriculum", data=df,
                     height=12, kind="bar", palette="Paired", )
    plt.title(title)
    return ax
//  [python]
print(dataset["sex"].describe())
sns.displot(x="sex", data=dataset)

print(dataset["embarked"].describe())
sns.displot(x="embarked", data=dataset)

sns.factorplot(
    data=dataset,
    y="pclass",
    hue="survived",
    kind="count",
    palette="pastel",
    edgecolor=".6",
)
//  [python]
print(dataset["sex"].describe())
sns.displot(x="sex", data=dataset)

print(dataset["embarked"].describe())
sns.displot(x="embarked", data=dataset)

sns.catplot(
    data=dataset,
    y="pclass",
    hue="survived",
    kind="count",
    palette="pastel",
    edgecolor=".6",
)
//  [python]
def output_cat_plot(f_name, f_type, df, x, y, hue_list=None, hue="group", line_y=None, y_label=None,
                    y_max=None, color_p="Set2", legend_f=False, legend_p="upper right", order_f="higher is better",
                    l_col=None, shape_ratio=1.4, font_ratio=1.8, y_min=0):

    sns.set(style="whitegrid", font_scale=font_ratio)
    if hue_list:
        g = sns.factorplot(x=x, y=y, hue=hue, hue_order=hue_list, data=df, kind=f_type, palette=color_p, ci="sd",
                        legend=legend_f, aspect=shape_ratio)
    else:
        g = sns.factorplot(x=x, y=y, hue=hue, data=df, kind=f_type, palette=color_p, ci="sd", legend=legend_f,
                        aspect=shape_ratio)

    # plot the line at specified x
    x_max = len(df[x].unique())
    if line_y:
        plt.plot([-1] + [i for i in range(x_max)] + [x_max - 0.5], [line_y for _ in range(x_max + 2)], "black")
    plt.xlim([-0.5, x_max - 0.5])

    # decide y limit
    if not y_max:
        y_max = max(df[y])

    if not y_min and y_min != 0:
        y_min = min(df[y])

    if y_max <= 1.1:
        y_ticks = [x / 10 for x in range(int(y_min * 10), 11) if x % 2 == 0]
        plt.ylim([y_min, 1.0])
        plt.yticks(y_ticks)
    elif y_max < 10:
        plt.ylim([y_min, y_max + 0.01])
    else:
        plt.ylim([y_min - 1, y_max + 1])
        y_ticks = list(range(int(y_min), int(y_max), int((y_max - y_min) / 6)))
        plt.yticks(y_ticks)

    if y_label:
        if order_f:
            plt.ylabel(y_label + " (" + order_f + ")")
        else:
            plt.ylabel(y_label)
    else:
        plt.ylabel("")

    plt.xlabel("")
    if not legend_f:  # bbox_to_anchor=(1.01, 0.6)
        if "outside" in legend_p:
            plt.legend(bbox_to_anchor=(1.01, 0.6))
        else:
            if l_col:
                plt.legend(loc=legend_p, ncol=l_col, borderaxespad=0.1,
                           handlelength=0.7, handletextpad=0.3, columnspacing=0.3)
            else:
                plt.legend(loc=legend_p, ncol=4, borderaxespad=0.05,
                           handlelength=0.7, handletextpad=0.05, columnspacing=0.3)

    plt.tight_layout()

    cur_f_path = f_name[0:f_name.rfind("/") + 1]
    if not os.path.exists(cur_f_path):
        directory = os.path.dirname(cur_f_path)
        pathlib.Path(directory).mkdir(parents=True, exist_ok=True)
    plt.savefig(f_name + ".pdf")
    plt.close()
//  [python]
def output_cat_plot(f_name, f_type, df, x, y, hue_list=None, hue="group", line_y=None, y_label=None,
                    y_max=None, color_p="Set2", legend_f=False, legend_p="upper right", order_f="higher is better",
                    l_col=None, shape_ratio=1.4, font_ratio=1.8, y_min=0):

    sns.set(style="whitegrid", font_scale=font_ratio)
    if hue_list:
        g = sns.catplot(x=x, y=y, hue=hue, hue_order=hue_list, data=df, kind=f_type, palette=color_p, ci="sd",
                        legend=legend_f, aspect=shape_ratio)
    else:
        g = sns.catplot(x=x, y=y, hue=hue, data=df, kind=f_type, palette=color_p, ci="sd", legend=legend_f,
                        aspect=shape_ratio)

    # plot the line at specified x
    x_max = len(df[x].unique())
    if line_y:
        plt.plot([-1] + [i for i in range(x_max)] + [x_max - 0.5], [line_y for _ in range(x_max + 2)], "black")
    plt.xlim([-0.5, x_max - 0.5])

    # decide y limit
    if not y_max:
        y_max = max(df[y])

    if not y_min and y_min != 0:
        y_min = min(df[y])

    if y_max <= 1.1:
        y_ticks = [x / 10 for x in range(int(y_min * 10), 11) if x % 2 == 0]
        plt.ylim([y_min, 1.0])
        plt.yticks(y_ticks)
    elif y_max < 10:
        plt.ylim([y_min, y_max + 0.01])
    else:
        plt.ylim([y_min - 1, y_max + 1])
        y_ticks = list(range(int(y_min), int(y_max), int((y_max - y_min) / 6)))
        plt.yticks(y_ticks)

    if y_label:
        if order_f:
            plt.ylabel(y_label + " (" + order_f + ")")
        else:
            plt.ylabel(y_label)
    else:
        plt.ylabel("")

    plt.xlabel("")
    if not legend_f:  # bbox_to_anchor=(1.01, 0.6)
        if "outside" in legend_p:
            plt.legend(bbox_to_anchor=(1.01, 0.6))
        else:
            if l_col:
                plt.legend(loc=legend_p, ncol=l_col, borderaxespad=0.1,
                           handlelength=0.7, handletextpad=0.3, columnspacing=0.3)
            else:
                plt.legend(loc=legend_p, ncol=4, borderaxespad=0.05,
                           handlelength=0.7, handletextpad=0.05, columnspacing=0.3)

    plt.tight_layout()

    cur_f_path = f_name[0:f_name.rfind("/") + 1]
    if not os.path.exists(cur_f_path):
        directory = os.path.dirname(cur_f_path)
        pathlib.Path(directory).mkdir(parents=True, exist_ok=True)
    plt.savefig(f_name + ".pdf")
    plt.close()
//  [python]
def visualize(df, cutoff, distance):
        df = df.loc[(df['cutoff'] == cutoff) & (df['distance'] == distance)]
        sns.factorplot(x="rec_type", y="value",
                    hue="discount", col="metric",
                    data=df, kind="boxen",
                    size=4, aspect=.7, col_wrap=3)
        plt.show()
//  [python]
def visualize(df, cutoff, distance):
        df = df.loc[(df['cutoff'] == cutoff) & (df['distance'] == distance)]
        sns.catplot(x="rec_type", y="value",
                    hue="discount", col="metric",
                    data=df, kind="boxen",
                    height=4, aspect=.7, col_wrap=3)
        plt.show()
//  [python]
def plot_benchmark(performance_df: pd.DataFrame, save_path: str, benchmark_name: str):
    performance_df['samples / sec'] = 1 / performance_df[DELTA_COL] * performance_df[BATCH_SIZE_COL]
    plt.figure(figsize=(performance_df[BATCH_SIZE_COL].nunique() * 6, 6))
    g = sns.FacetGrid(performance_df, col=BATCH_SIZE_COL, hue=NAME_COL)
    g.map(sns.pointplot, WORKER_COL, 'samples / sec')
    g.add_legend()
    plt.suptitle(f'Benchmark: {benchmark_name}', weight='bold', size='large', y=1.05)
    print(f'Saving figure to {save_path}')
    plt.savefig(save_path, dpi=200, bbox_inches='tight')
//  [python]
def plot_benchmark(performance_df: pd.DataFrame, save_path: str, benchmark_name: str):
    performance_df['samples / sec'] = 1 / performance_df[DELTA_COL] * performance_df[BATCH_SIZE_COL]
    plt.figure(figsize=(performance_df[BATCH_SIZE_COL].nunique() * 6, 6))
    sns.catplot(
        data=performance_df, kind='point',
        hue=NAME_COL, y='samples / sec', x=WORKER_COL, col=BATCH_SIZE_COL,
    )
    plt.suptitle(f'Benchmark: {benchmark_name}', weight='bold', size='large', y=1.05)
    print(f'Saving figure to {save_path}')
    plt.savefig(save_path, dpi=200, bbox_inches='tight')
//  [python]
def plot_ecl_distribution_by_app_v1(self, df_ecl):
        order_list = ["OP", "IP", "SD", "SL", "WM"]
        sns.set(font_scale=1.2)
        sns.set_style("whitegrid")

        # Plot categorical figure
        g = sns.factorplot(
            x="app",
            y="ratio",
            hue="ECL",
            col="operator",
            data=df_ecl,
            kind="bar",
            palette="Set3",
            order=order_list,
            legend_out=False,
            linewidth=0.5,
            edgecolor=".4",
        )

        # Tweak the figure
        g.set_axis_labels("", "")
        g.set_titles("Operator={col_name}")
        # g.set_xlabel('Location profile', fontsize=self.text_size)
        g.set_xticklabels(
            [
                "Outdoor-\nParking",
                "Indoor-\nParking",
                "Indoor-\nSmoke\nsensing",
                "Indoor-\nSmart\nlock",
                "Indoor-\nWater\nmeter",
            ],
            fontsize=self.text_size + 3,
        )
        g.set(ylim=(0, 1))
        g.axes[0, 1].set_xlabel("Location Profile", fontsize=self.text_size + 7)
        g.axes[0, 0].set_ylabel("Percentage", fontsize=self.text_size + 7)
        g.fig.tight_layout()

        plt.savefig(
            self.global_path
            + "Docs/LaTeX Papers/nbiot_paper_first_draft/assets/ecl_dist_by_app_op.pdf"
        )
        plt.show()
        plt.close()
//  [python]
def plot_ecl_distribution_by_app_v1(self, df_ecl):
        order_list = ["OP", "IP", "SD", "SL", "WM"]
        sns.set(font_scale=1.2)
        sns.set_style("whitegrid")

        # Plot categorical figure
        g = sns.catplot(
            x="app",
            y="ratio",
            hue="ECL",
            col="operator",
            data=df_ecl,
            kind="bar",
            palette="Set3",
            order=order_list,
            legend_out=False,
            linewidth=0.5,
            edgecolor=".4",
        )

        # Tweak the figure
        g.set_axis_labels("", "")
        g.set_titles("Operator={col_name}")
        # g.set_xlabel('Location profile', fontsize=self.text_size)
        g.set_xticklabels(
            [
                "Outdoor-\nParking",
                "Indoor-\nParking",
                "Indoor-\nSmoke\nsensing",
                "Indoor-\nSmart\nlock",
                "Indoor-\nWater\nmeter",
            ],
            fontsize=self.text_size + 3,
        )
        g.set(ylim=(0, 1))
        g.axes[0, 1].set_xlabel("Location Profile", fontsize=self.text_size + 7)
        g.axes[0, 0].set_ylabel("Percentage", fontsize=self.text_size + 7)
        g.fig.tight_layout()

        plt.savefig(
            self.global_path
            + "Docs/LaTeX Papers/nbiot_paper_first_draft/assets/ecl_dist_by_app_op.pdf"
        )
        plt.show()
        plt.close()
//  [python]
def generate_cumulative_bar(
        self,
        benchmarking_results: List[BenchmarkRunResults],
        benchmark_generator: BenchmarkRunOutputGenerator,
        title: str = None,
    ) -> None:
        """
        Generate a cumulative bar plot.

        Args:
            benchmarking_results (List[BenchmarkRunResults]): List of benchmarking results for multiple runs.
            benchmark_generator (BenchmarkRunOutputGenerator): Object containing benchmarking output generation details.
            title (str, optional): Title for the generated plot. Defaults to None.
        """
        for benchmark_result in benchmarking_results:
            self._generate_cumulative_bar_plot_data(benchmark_result)
        stats_df = pd.DataFrame(self.stats)
        sns.barplot(
            data=stats_df,
            x="Rank",
            y="Percentage",
            hue="Run",
            palette=self.palette_hex_codes,
            edgecolor="white",
        )
        plt.legend(loc="upper center", bbox_to_anchor=(0.5, -0.15), ncol=3, title="Run")
        if title is None:
            plt.title(
                f"{benchmark_generator.prioritisation_type_file_prefix.capitalize()} Cumulative Rank Stats"
            )
        else:
            plt.title(title, loc="center", fontsize=15)
        plt.ylim(0, 1)
        plt.savefig(
            f"{benchmark_generator.prioritisation_type_file_prefix}_rank_stats.svg",
            format="svg",
            bbox_inches="tight",
        )
//  [python]
def generate_cumulative_bar(
        self,
        benchmarking_results: List[BenchmarkRunResults],
        benchmark_generator: BenchmarkRunOutputGenerator,
        title: str = None,
    ) -> None:
        """
        Generate a cumulative bar plot.

        Args:
            benchmarking_results (List[BenchmarkRunResults]): List of benchmarking results for multiple runs.
            benchmark_generator (BenchmarkRunOutputGenerator): Object containing benchmarking output generation details.
            title (str, optional): Title for the generated plot. Defaults to None.
        """
        for benchmark_result in benchmarking_results:
            self._generate_cumulative_bar_plot_data(benchmark_result)
        stats_df = pd.DataFrame(self.stats)
        sns.catplot(
            data=stats_df,
            kind="bar",
            x="Rank",
            y="Percentage",
            hue="Run",
            palette=self.palette_hex_codes,
            edgecolor="white",
            legend=False,
        ).set(xlabel="Rank", ylabel=benchmark_generator.y_label)
        plt.legend(loc="upper center", bbox_to_anchor=(0.5, -0.15), ncol=3, title="Run")
        if title is None:
            plt.title(
                f"{benchmark_generator.prioritisation_type_file_prefix.capitalize()} Cumulative Rank Stats"
            )
        else:
            plt.title(title, loc="center", fontsize=15)
        plt.ylim(0, 1)
        plt.savefig(
            f"{benchmark_generator.prioritisation_type_file_prefix}_rank_stats.svg",
            format="svg",
            bbox_inches="tight",
        )
//  [python]
def unique_value_count(self):   
        #Information on the data type
        display(('--------------------Plot Unique Value Counts and DataType for each Feature--------------------'))
        col_info=pd.DataFrame(columns=['col_name','label','unique_values'])
        for col in self.dataframe.columns:
            row = [col, self.dataframe[col].dtype , self.dataframe[col].nunique()]
            col_info.loc[len(col_info)] = row

        col_info['label']=col_info['label'].astype('str')
        s.factorplot(x='col_name', y='unique_values', hue='label', kind='bar', data=col_info, size=6, aspect=col_info.shape[0]/10+2)
            
        plt.xticks(rotation=90)
        plt.show()

        display(('--------------------Unique Values for each categorical feature--------------------'))
        for col in list(self.dataframe.select_dtypes(include=[np.object,np.bool]).columns):
            print('Column Name: {} : {}'.format(col,self.dataframe[col].unique()))
//  [python]
def unique_value_count(self):   
        #Information on the data type
        display(('--------------------Plot Unique Value Counts and DataType for each Feature--------------------'))
        col_info=pd.DataFrame(columns=['col_name','label','unique_values'])
        for col in self.dataframe.columns:
            row = [col, self.dataframe[col].dtype , self.dataframe[col].nunique()]
            col_info.loc[len(col_info)] = row

        col_info['label']=col_info['label'].astype('str')
        sns.catplot(x='col_name', y='unique_values', hue='label', kind='bar', data=col_info, height=6, aspect=col_info.shape[0]/10+2)
            
        plt.xticks(rotation=90)
        plt.show()

        display(('--------------------Unique Values for each categorical feature--------------------'))
        for col in list(self.dataframe.select_dtypes(include=[np.object,np.bool]).columns):
            print('Column Name: {} : {}'.format(col,self.dataframe[col].unique()))
//  [python]
def generate_non_cumulative_bar(
        self,
        benchmarking_results: List[BenchmarkRunResults],
        benchmark_generator: BenchmarkRunOutputGenerator,
        title: str = None,
    ) -> None:
        """
        Generate a non-cumulative bar plot.

        Args:
            benchmarking_results (List[BenchmarkRunResults]): List of benchmarking results for multiple runs.
            benchmark_generator (BenchmarkRunOutputGenerator): Object containing benchmarking output generation details.
            title (str, optional): Title for the generated plot. Defaults to None.
        """
        for benchmark_result in benchmarking_results:
            self._generate_non_cumulative_bar_plot_data(benchmark_result)

        stats_df = pd.DataFrame(self.stats)
        sns.barplot(
            data=stats_df,
            x="Rank",
            y="Percentage",
            hue="Run",
            palette=self.palette_hex_codes,
            edgecolor="white",
        )
        plt.legend(loc="upper center", bbox_to_anchor=(0.5, -0.15), ncol=3, title="Run")
        if title is None:
            plt.title(
                f"{benchmark_generator.prioritisation_type_file_prefix.capitalize()} Non-Cumulative Rank Stats"
            )
        else:
            plt.title(title, loc="center", fontsize=15)
        plt.ylim(0, 1)
        plt.savefig(
            f"{benchmark_generator.prioritisation_type_file_prefix}_rank_stats.svg",
            format="svg",
            bbox_inches="tight",
        )
//  [python]
def generate_non_cumulative_bar(
        self,
        benchmarking_results: List[BenchmarkRunResults],
        benchmark_generator: BenchmarkRunOutputGenerator,
        title: str = None,
    ) -> None:
        """
        Generate a non-cumulative bar plot.

        Args:
            benchmarking_results (List[BenchmarkRunResults]): List of benchmarking results for multiple runs.
            benchmark_generator (BenchmarkRunOutputGenerator): Object containing benchmarking output generation details.
            title (str, optional): Title for the generated plot. Defaults to None.
        """
        for benchmark_result in benchmarking_results:
            self._generate_non_cumulative_bar_plot_data(benchmark_result)

        stats_df = pd.DataFrame(self.stats)
        sns.catplot(
            data=stats_df,
            kind="bar",
            x="Rank",
            y="Percentage",
            hue="Run",
            palette=self.palette_hex_codes,
            edgecolor="white",
            legend=False,
        ).set(xlabel="Rank", ylabel=benchmark_generator.y_label)
        plt.legend(loc="upper center", bbox_to_anchor=(0.5, -0.15), ncol=3, title="Run")
        if title is None:
            plt.title(
                f"{benchmark_generator.prioritisation_type_file_prefix.capitalize()} Non-Cumulative Rank Stats"
            )
        else:
            plt.title(title, loc="center", fontsize=15)
        plt.ylim(0, 1)
        plt.savefig(
            f"{benchmark_generator.prioritisation_type_file_prefix}_rank_stats.svg",
            format="svg",
            bbox_inches="tight",
        )
//  [python]
def bar_chart(self):
        display(('--------------------bar chart of categorial variables--------------------'))
   
        for x in self.categorical_variables:
           # if x != y:
            sns.countplot(x=x, palette="deep", data=self.dataframe);
            plt.xlabel(x)
            plt.xticks(rotation='vertical')
            plt.ylabel('Frequency')
            plt.title('Bar chart of '+ x ,size=16, y=1.05)
            plt.grid(True)
            plt.show()
            display('==============================================================================================================')
//  [python]
def bar_chart(self):
        display(('--------------------bar chart of categorial variables--------------------'))
   
        for x in self.categorical_variables:
           # if x != y:
            sns.catplot(x=x, kind="count", palette="deep", data=self.dataframe,height=5, aspect=2);
            plt.xlabel(x)
            plt.xticks(rotation='vertical')
            plt.ylabel('Frequency')
            plt.title('Bar chart of '+ x ,size=16, y=1.05)
            plt.grid(True)
            plt.show()
            display('==============================================================================================================')
//  [python]
def make(
        self,
        save: bool = True,
        show: bool = False,
        out_path: str | None = None,
    ) -> tuple[List[sns.FacetGrid], pd.DataFrame]:
        """Make the plot for a given validation type.

        Args:
            property_name (str):
                name of the property to plot (should correspond to the prefix of
                the column names in the data files).
            save (bool):
                Whether to save the plot to a file.
            show (bool):
                Whether to display the plot.
            out_path (str | None):
                Path to save the plots to, e.g. "results/plot.png", the plot will be
                saved to this path with the metric name appended before the extension,
                e.g. "results/plot_roc_auc.png". If `None`, the plots will be saved to
                each model's output directory.

        Returns:
            figures (list[sns.FacetGrid]):
                the seaborn FacetGrid objects used to make the plot
            pd.DataFrame:
                A dataframe containing the summary data generated.
        """
        # Get summary with calculated metrics
        if not hasattr(self, "summary"):
            self.getSummary()

        figures = []
        for metric in self.metrics:
            # check if metric in summary dataframe
            if metric not in self.summary.columns:
                print(f"Metric {metric} not in summary dataframe, skipping")
                continue

            # plot the results
            g = sns.factorplot(
                data=self.summary,
                x="Class",
                y=metric,
                hue="Set",
                col="Property",
                row="Model",
                kind="bar",
                margin_titles=True,
                sharex=False,
                sharey=False,
            )
            # set y range max to 1 for each plot, but don't set min to 0 as some metrics can be negative
            for ax in g.axes_dict.values():
                y_min, y_max = ax.get_ylim()
                ax.set_ylim(y_min, 1)
            figures.append(g)
            if save:
                # add metric to out_path if it exists before the extension
                if out_path is not None:
                    plt.savefig(
                        os.path.splitext(out_path)[0] + f"_{metric}.png", dpi=300
                    )
                else:
                    for model in self.models:
                        plt.savefig(f"{model.outPrefix}_{metric}.png", dpi=300)
            if show:
                plt.show()
                plt.clf()
        return figures, self.summary
//  [python]
def make(
        self,
        save: bool = True,
        show: bool = False,
        out_path: str | None = None,
    ) -> tuple[List[sns.FacetGrid], pd.DataFrame]:
        """Make the plot for a given validation type.

        Args:
            property_name (str):
                name of the property to plot (should correspond to the prefix of
                the column names in the data files).
            save (bool):
                Whether to save the plot to a file.
            show (bool):
                Whether to display the plot.
            out_path (str | None):
                Path to save the plots to, e.g. "results/plot.png", the plot will be
                saved to this path with the metric name appended before the extension,
                e.g. "results/plot_roc_auc.png". If `None`, the plots will be saved to
                each model's output directory.

        Returns:
            figures (list[sns.FacetGrid]):
                the seaborn FacetGrid objects used to make the plot
            pd.DataFrame:
                A dataframe containing the summary data generated.
        """
        # Get summary with calculated metrics
        if not hasattr(self, "summary"):
            self.getSummary()

        figures = []
        for metric in self.metrics:
            # check if metric in summary dataframe
            if metric not in self.summary.columns:
                print(f"Metric {metric} not in summary dataframe, skipping")
                continue

            # plot the results
            g = sns.catplot(
                self.summary,
                x="Class",
                y=metric,
                hue="Set",
                col="Property",
                row="Model",
                kind="bar",
                margin_titles=True,
                sharex=False,
                sharey=False,
            )
            # set y range max to 1 for each plot, but don't set min to 0 as some metrics can be negative
            for ax in g.axes_dict.values():
                y_min, y_max = ax.get_ylim()
                ax.set_ylim(y_min, 1)
            figures.append(g)
            if save:
                # add metric to out_path if it exists before the extension
                if out_path is not None:
                    plt.savefig(
                        os.path.splitext(out_path)[0] + f"_{metric}.png", dpi=300
                    )
                else:
                    for model in self.models:
                        plt.savefig(f"{model.outPrefix}_{metric}.png", dpi=300)
            if show:
                plt.show()
                plt.clf()
        return figures, self.summary
//  [python]
def bar_chart_2_variables(self):
        display(('--------------------bar plot of each categorical variables segmented by another categorical variables--------------------'))

        for x,y in iter.combinations(self.include_variables,2):
           # if x != y:
            sns.factorplot(x=x, hue=y, kind="count", palette="deep", data=self.dataframe,size=5, aspect=2);
            plt.xticks(rotation='vertical')
            plt.xlabel(x)
            plt.ylabel(y)
            plt.title('Bar plot of '+ x + ' and ' + y,size=16, y=1.05)
            plt.grid(True)
            plt.show()
//  [python]
def bar_chart_2_variables(self):
        display(('--------------------bar plot of each categorical variables segmented by another categorical variables--------------------'))

        for x,y in iter.combinations(self.include_variables,2):
           # if x != y:
            sns.catplot(x=x, hue=y, kind="count", palette="deep", data=self.dataframe,height=5, aspect=2);
            plt.xticks(rotation='vertical')
            plt.xlabel(x)
            plt.ylabel(y)
            plt.title('Bar plot of '+ x + ' and ' + y,size=16, y=1.05)
            plt.grid(True)
            plt.show()
//  [python]
def bar_chart_independent_label(self):
        display(('--------------------bar plot of each categorical variables segmented by label--------------------'))
        y=label;
        for x in self.include_variables:
           # if x != y:
            sns.factorplot(x=x, hue=y, kind="count", palette="deep", data=self.dataframe,size=5, aspect=2);
            plt.xticks(rotation='vertical')
            plt.xlabel(x)
            plt.ylabel(y)
            plt.title('Bar plot of '+ x + ' and ' + y,size=16, y=1.05)
            plt.grid(True)
            plt.show()
//  [python]
def bar_chart_independent_label(self):
        display(('--------------------bar plot of each categorical variables segmented by label--------------------'))
        y=label;
        for x in self.include_variables:
           # if x != y:
            sns.catplot(x=x, hue=y, kind="count", palette="deep", data=self.dataframe,height=5, aspect=2);
            plt.xticks(rotation='vertical')
            plt.xlabel(x)
            plt.ylabel(y)
            plt.title('Bar plot of '+ x + ' and ' + y,size=16, y=1.05)
            plt.grid(True)
            plt.show()
//  [python]
def make_bar_sn_plot(df):
    '''note the fake 0.5 are b/c of Illustrator import error for 0 values.'''
    
    df = df[(df.ID.str.contains('T_L_Sml')) & (df.EXPERIMENT == 'bulk') &
            (df.CLADE_FIG != 'ZONK') & (df.SUB_CLADE_FIG == 'Founder')]\
            [['CONSIDERED_MAF_TISSUE', 'VARIANT_ORDER_FIG', 'CLADE_FIG',
              'SUB_CLADE_FIG']].sort_values('VARIANT_ORDER_FIG')
    
    df_sum = pd.DataFrame(data={'CONSIDERED_MAF_TISSUE':
                                [df.CONSIDERED_MAF_TISSUE.sum(), 0.5, 0.5, 0.5,
                                 0.5, 0.5, 0.5, 0.5, 0.5],
                                'VARIANT_ORDER_FIG': [-1 for i in range(9)],
                                'CLADE_FIG': ['Sum', 'I', 'II', 'III', 'IV',
                                              'V', 'VI', 'VII', 'Sum'],
                                'SUB_CLADE_FIG': ['A', 'A', 'A', 'A', 'A', 'A',
                                                  'A', 'A', 'Founder']})
        
    df = df.append(df_sum).sort_values('VARIANT_ORDER_FIG')
    
    df['CONSIDERED_MAF_TISSUE'] = df.CONSIDERED_MAF_TISSUE**0.5
    
    sns.barplot(x='SUB_CLADE_FIG', y='CONSIDERED_MAF_TISSUE', hue='CLADE_FIG',
                data=df,
                palette=sns.color_palette(['0.4', 'b', 'g', 'r', 'y',
                                           'xkcd:purple', 'xkcd:cyan', '0.8']),
                edgecolor='k')
    
    plt.ylim(0, 0.5)
    plt.yticks(ticks=[0, 0.01**0.5, 0.05**0.5, 0.2**0.5, 0.5**0.5],
               labels=['0.00', '0.01', '0.05', '0.20', '0.50'])
    plt.ylabel('L-T-Sml AF (sqrt-t)')
    
    plt.show()