//  [python]
def output_figure1():
    def plot_figure1(alg, score, df, png_name):
        df_melted = df[['exp_name', 'wrong_prior', 'wrong_query']].melt(
            id_vars='exp_name', var_name='metric', value_name='value')

        plt.figure()
        catplot = sns.catplot(x='exp_name', y='value', hue='metric', data=df_melted, kind='bar',
                                ci='sd', palette=sns.color_palette(), legend_out=False, height=5, aspect=3)

        # Looping over the bars to add the values on top
        for i, bar in enumerate(catplot.ax.patches):
            catplot.ax.text(bar.get_x() + bar.get_width() / 2., bar.get_height(),
                            f'{bar.get_height():.2f}', ha='center', va='bottom')

        plt.xticks()
        catplot.set_axis_labels("Dataset", "num")
        # rotate x label
        catplot.set_xticklabels(rotation=15, ha='right')
        # Add some space at the top for the p-values
        # catplot.set(ylim=(0, df['shd'].max() + 0.1))
        catplot.fig.suptitle(f"{alg} {score} wrong number")

        plt.legend()
        catplot.savefig(png_name)
        plt.close()
        rprint(
            f"📊📊 LLM catplot saved to [italic blue]{png_name}[/italic blue]")

    for alg, score in alg_score_list:
        df_all = pd.DataFrame()
        for dataset in dataset_list:
            for i in range(2):
                datasize = dataset2size[i][dataset]
                input_path = "out/result-all.csv"
                df = pd.read_csv(input_path)
                df = df[df["alg"] == alg]
                df = df[df["score"] == score]
                df = df[df["d"] == dataset]
                df = df[df["s"] == datasize]
                df["exp name"] = df.apply(
                    lambda row: f"{row['d']}-{row['s']}", axis=1)
                df["exp name duo"] = df.apply(
                    lambda row: f"{row['d']}", axis=1)

                df = df[df["LLM"].isin(["with", "both"])]

                df = df[['exp name', "exp name duo", 'iter', 'exist_prior', 'exist_prior_wrong',
                        'forb_prior', 'forb_prior_wrong', 'uncertain_query', 'correct_query', 'wrong_query']]

                df["prior_wrong"] = df["exist_prior_wrong"] + \
                    df["forb_prior_wrong"]
                df = df[['exp name', "exp name duo",
                         'prior_wrong', 'wrong_query']]
                df = df.rename(
                    columns={"exp name": "exp_name", "exp name duo": "exp_name_duo",
                             "prior_wrong": "wrong_prior", "wrong_query": "wrong_query"})
                # df = df.set_index("exp name")
                df_all = pd.concat([df_all, df], axis=0)
        df_duo = df_all[['exp_name_duo', 'wrong_prior', 'wrong_query']].rename(
            columns={"exp_name_duo": "exp_name"})
        # save to csv
        df_all[['exp_name', 'wrong_prior', 'wrong_query']].to_csv(
            f"out/paper/figure1/figure1-{alg}-{score}.csv", index=False)
        df_duo.to_csv(
            f"out/paper/figure1/figure1-{alg}-{score}-duo.csv", index=False)
        # seaborn barplot
        plot_figure1(alg, score, df_all,  f"img/figure1/{alg}-{score}.png")
        plot_figure1(alg, score, df_duo,  f"img/figure1/{alg}-{score}-duo.png")