jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def plot_avg_coverage_vs_time_broken(hwf_cov_df, rfuzz_cov_df, time_units="m"):
  print(yellow("Generating plot ..."))

  # Set plot style and extract only HDL line coverage
  # sns.set_theme(context="notebook", style="darkgrid")
  hdl_cov_df = pd.concat([hwf_cov_df, rfuzz_cov_df])

  # create subplots
  fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True, figsize=(6, 4))

  # create figure and plot the data
  # fig, ax = plt.subplots(1, 1, figsize=(6, 4))
  sns.lineplot(data=hdl_cov_df,
               x=TIME_LABEL,
               y=COVERAGE_LABEL,
               hue=TOPLEVEL_LABEL,
               style=FUZZER_LABEL,
               ax=ax1)
  sns.lineplot(data=hdl_cov_df,
               x=TIME_LABEL,
               y=COVERAGE_LABEL,
               hue=TOPLEVEL_LABEL,
               style=FUZZER_LABEL,
               ax=ax2)

  # set axis ranges
  ax1.set_ylim(0.3, 1.0)
  ax2.set_ylim(0, 0.05)

  # hide the spines between the two axes
  ax1.spines['bottom'].set_visible(False)
  ax2.spines['top'].set_visible(False)
  ax1.xaxis.tick_top()
  ax1.tick_params(labeltop=False)
  ax2.xaxis.tick_bottom()

  # format the plot
  if time_units == "m":
    time_units_label = "min."
  elif time_units == "h":
    time_units_label = "hours"
  else:
    time_units_label = "s"
  # ax1.set_xlabel(TIME_LABEL + " (%s)" % time_units_label,
  # fontsize=LABEL_FONT_SIZE)
  # ax1.set_ylabel("HDL Line " + COVERAGE_LABEL, fontsize=LABEL_FONT_SIZE)
  # ax1.tick_params("x", labelsize=TICK_FONT_SIZE)
  # ax1.tick_params("y", labelsize=TICK_FONT_SIZE)
  # plt.legend(fontsize=LEGEND_FONT_SIZE,
  # title_fontsize=LEGEND_TITLE_FONT_SIZE,
  # bbox_to_anchor=(1.01, 0.75),
  # loc='upper left')
  plt.tight_layout()

  # save the plot
  plt.savefig(PLOT_FILE_NAME, format=PLOT_FORMAT)
  print(green("Done."))
  print(LINE_SEP)
//  [python]
def main():
    parser = argparse.ArgumentParser(
        description="Visualize benchmark score (reported by the METRIC macro) changes in the log.")
    parser.add_argument("--log", required=True, help="The boot log.")
    parser.add_argument("--key", required=True, help="The metric key.")
    args = parser.parse_args()

    ys = []
    for line in open(args.log).readlines():
        try:
            data = json.loads(line)
        except json.JSONDecodeError:
            continue

        if data.get("type") != "metric":
            continue
        if data.get("key") != args.key:
            continue

        ys.append(data["value"])

    data = pd.DataFrame({"x": np.arange(len(ys)), "score": ys})
    sns.plt.plot(data["x"], data["score"])
    plt.show()
//  [python]
def main():
    parser = argparse.ArgumentParser(
        description="Visualize benchmark score (reported by the METRIC macro) changes in the log.")
    parser.add_argument("--log", required=True, help="The boot log.")
    parser.add_argument("--key", required=True, help="The metric key.")
    args = parser.parse_args()

    ys = []
    for line in open(args.log).readlines():
        try:
            data = json.loads(line)
        except json.JSONDecodeError:
            continue

        if data.get("type") != "metric":
            continue
        if data.get("key") != args.key:
            continue

        ys.append(data["value"])

    data = pd.DataFrame({"x": np.arange(len(ys)), "score": ys})
    sns.lineplot(data=data, x="x", y="score")
    plt.show()
//  [python]
def plot(gen_name):
    df_sav = pd.read_csv('vespa_msa/'+gen_name+'_sav_scores.csv',header=None)
    df_sav_avg = df_sav.mean()
    sav_avg_arr = np.array(list(df_sav_avg.values))
    df_cons = pd.read_csv('vespa_msa/'+gen_name+'_cons_scores.csv',header=None)
    df_cons_avg = df_cons.mean()
    cons_avg_arr = np.array(list(df_cons_avg.values))
    spearman_corr = scipy.stats.mstats.spearmanr(cons_avg_arr,sav_avg_arr)
    df_all_avg = pd.DataFrame()
    df_all_avg['Average Mutant SAV Scores'] = list(df_sav_avg.values)
    df_all_avg['Average Wildtype Conservation Class'] = list(df_cons_avg.values)

    ## Plotting Positional SAV Effect and Conservation Classes ##
    plt.figure(figsize=(15,8))
    sns.set(style="darkgrid")
    plt.plot(df_all_avg['Average Mutant SAV Scores'], label='Average Mutant SAV Scores')
    plt.plot(df_all_avg['Average Wildtype Conservation Class'], label='Average Wildtype Conservation Class')
    plt.xlabel('MSA Position Index', fontsize=16)
    plt.title('Positional SAV Effect and Conservation')
    plt.legend() 
    plt.savefig(gen_name+'_sav_cons_score.png')

    ## Plotting Relation Between SAV Effect Scores and Conservation Class Per Position ##
    plt.figure(figsize=(15,8))
    sns.set(style="whitegrid")
    p = sns.regplot(x= list(df_all_avg['Average Mutant SAV Scores'].values),y=list(df_all_avg['Average Wildtype Conservation Class'].values),color="lightseagreen")
    #calculate slope and intercept of regression equation
    slope, intercept, r, p, sterr = scipy.stats.linregress(x=p.get_lines()[0].get_xdata(),y=p.get_lines()[0].get_ydata())
    #add regression equation to plot
    plt.text(0.25, 7, 'y = ' + str(round(intercept,3)) + ' + (' + str(round(slope,3)) + ')x', fontsize=15, color='teal',fontstyle = "oblique")
    ## Spearman Correlation Between  Postional Average SAV scores and Average Conservation Classes ##
    plt.text(0.25, 6, 'Spearman correlation = '+str(round(spearman_corr.statistic,3)), fontsize=15, color='teal',fontstyle = "oblique")
    plt.xlabel('Positional SAV Scores', fontsize=14)
    plt.ylabel('Positional Conservation Scores', fontsize=14)
    plt.savefig(gen_name+'_corr_score.png')
//  [python]
def plot(gen_name):
    df_sav = pd.read_csv('vespa_msa/'+gen_name+'_sav_scores.csv',header=None)
    df_sav_avg = df_sav.mean()
    sav_avg_arr = np.array(list(df_sav_avg.values))
    df_cons = pd.read_csv('vespa_msa/'+gen_name+'_cons_scores.csv',header=None)
    df_cons_avg = df_cons.mean()
    cons_avg_arr = np.array(list(df_cons_avg.values))
    spearman_corr = scipy.stats.mstats.spearmanr(cons_avg_arr,sav_avg_arr)
    df_all_avg = pd.DataFrame()
    df_all_avg['Average Mutant SAV Scores'] = list(df_sav_avg.values)
    df_all_avg['Average Wildtype Conservation Class'] = list(df_cons_avg.values)

    ## Plotting Positional SAV Effect and Conservation Classes ##
    plt.figure(figsize=(15,8))
    sns.set(style="darkgrid")
    sns.lineplot(data=df_all_avg)
    plt.xlabel('MSA Position Index', fontsize=16)
    plt.title('Positional SAV Effect and Conservation')
    plt.legend() 
    plt.savefig(gen_name+'_sav_cons_score.png')

    ## Plotting Relation Between SAV Effect Scores and Conservation Class Per Position ##
    plt.figure(figsize=(15,8))
    sns.set(style="whitegrid")
    p = sns.regplot(x= list(df_all_avg['Average Mutant SAV Scores'].values),y=list(df_all_avg['Average Wildtype Conservation Class'].values),color="lightseagreen")
    #calculate slope and intercept of regression equation
    slope, intercept, r, p, sterr = scipy.stats.linregress(x=p.get_lines()[0].get_xdata(),y=p.get_lines()[0].get_ydata())
    #add regression equation to plot
    plt.text(0.25, 7, 'y = ' + str(round(intercept,3)) + ' + (' + str(round(slope,3)) + ')x', fontsize=15, color='teal',fontstyle = "oblique")
    ## Spearman Correlation Between  Postional Average SAV scores and Average Conservation Classes ##
    plt.text(0.25, 6, 'Spearman correlation = '+str(round(spearman_corr.statistic,3)), fontsize=15, color='teal',fontstyle = "oblique")
    plt.xlabel('Positional SAV Scores', fontsize=14)
    plt.ylabel('Positional Conservation Scores', fontsize=14)
    plt.savefig(gen_name+'_corr_score.png')
//  [python]
def main():
    plt.figure()
    num_site = len(sites_fl)
    i = 1
    # add event files

    data = {"Config": [], "Epoch": [], "Dice": []}

    for site in sites_fl:
        # clear data for each site
        data = {"Config": [], "Epoch": [], "Dice": []}
        for config, exp in experiments.items():
            spec_site = exp.get("site", None)
            if spec_site is not None:
                record_path = os.path.join(
                    client_results_root + config, "simulate_job", client_pre + spec_site, "events.*"
                )
            else:
                record_path = os.path.join(client_results_root + config, "simulate_job", client_pre + site, "events.*")

            eventfile = glob.glob(record_path, recursive=True)
            print(record_path, len(eventfile))
            assert len(eventfile) == 1, "No unique event file found!"
            eventfile = eventfile[0]
            print("adding", eventfile)
            add_eventdata(data, config, eventfile, tag=exp["tag"])

        ax = plt.subplot(1, num_site, i)
        ax.set_title(site)
        for config_val in data["Config"]:
            subset = data[data["Config"] == config_val]
            plt.plot(subset["Epoch"],subset["Dice"], label=config_val)
        plt.legend()

        # ax.set_xlim([0, 1000])
        i = i + 1
    plt.subplots_adjust(hspace=0.3)
    plt.show()
//  [python]
def main():
    plt.figure()
    num_site = len(sites_fl)
    i = 1
    # add event files

    data = {"Config": [], "Epoch": [], "Dice": []}

    for site in sites_fl:
        # clear data for each site
        data = {"Config": [], "Epoch": [], "Dice": []}
        for config, exp in experiments.items():
            spec_site = exp.get("site", None)
            if spec_site is not None:
                record_path = os.path.join(
                    client_results_root + config, "simulate_job", client_pre + spec_site, "events.*"
                )
            else:
                record_path = os.path.join(client_results_root + config, "simulate_job", client_pre + site, "events.*")

            eventfile = glob.glob(record_path, recursive=True)
            print(record_path, len(eventfile))
            assert len(eventfile) == 1, "No unique event file found!"
            eventfile = eventfile[0]
            print("adding", eventfile)
            add_eventdata(data, config, eventfile, tag=exp["tag"])

        ax = plt.subplot(1, num_site, i)
        ax.set_title(site)
        sns.lineplot(x="Epoch", y="Dice", hue="Config", data=data)
        # ax.set_xlim([0, 1000])
        i = i + 1
    plt.subplots_adjust(hspace=0.3)
    plt.show()
//  [python]
def plot_train_result(self):
        """Function to plot the training result."""
        algo = self.algo_list
        path = self.config.path_result
        result = self.config.path_figures
        data = [self.config.dataset_name]

        files = os.listdir(str(path))
        files_lwcase = [f.lower() for f in files]
        for d in data:
            df = pd.DataFrame()
            for a in algo:
                file_no = len([c for c in files_lwcase if a.lower() in c if 'training' in c])
                if file_no < 1:
                    continue
                file_path = str(path / (a.lower() + '_Training_results_' + str(file_no - 1) + '.csv'))
                if os.path.exists(file_path):
                    with open(str(path / (a.lower() + '_Training_results_' + str(file_no - 1) + '.csv')), 'r') as fh:
                        df_2 = pd.read_csv(fh)
                    if df.empty:
                        df['Epochs'] = df_2['Epochs']
                        df['Loss'] = df_2['Loss']
                        df['Algorithm'] = [a] * len(df_2)
                    else:
                        df_3 = pd.DataFrame()
                        df_3['Epochs'] = df_2['Epochs']
                        df_3['Loss'] = df_2['Loss']
                        df_3['Algorithm'] = [a] * len(df_2)
                        frames = [df, df_3]
                        df = pd.concat(frames)
            plt.figure()
            s.lineplot(x="Epochs", y="Loss", hue="Algorithm", markers=True, dashes=False, data=df)
            files = os.listdir(str(result))
            files_lwcase = [f.lower() for f in files]
            file_no = len([c for c in files_lwcase if d.lower() in c if 'training' in c])
            plt.savefig(str(result / (d + '_training_loss_plot_' + str(file_no) + '.pdf')), bbox_inches='tight', dpi=300)
//  [python]
def plot_train_result(self):
        """Function to plot the training result."""
        algo = self.algo_list
        path = self.config.path_result
        result = self.config.path_figures
        data = [self.config.dataset_name]

        files = os.listdir(str(path))
        files_lwcase = [f.lower() for f in files]
        for d in data:
            df = pd.DataFrame()
            for a in algo:
                file_no = len([c for c in files_lwcase if a.lower() in c if 'training' in c])
                if file_no < 1:
                    continue
                file_path = str(path / (a.lower() + '_Training_results_' + str(file_no - 1) + '.csv'))
                if os.path.exists(file_path):
                    with open(str(path / (a.lower() + '_Training_results_' + str(file_no - 1) + '.csv')), 'r') as fh:
                        df_2 = pd.read_csv(fh)
                    if df.empty:
                        df['Epochs'] = df_2['Epochs']
                        df['Loss'] = df_2['Loss']
                        df['Algorithm'] = [a] * len(df_2)
                    else:
                        df_3 = pd.DataFrame()
                        df_3['Epochs'] = df_2['Epochs']
                        df_3['Loss'] = df_2['Loss']
                        df_3['Algorithm'] = [a] * len(df_2)
                        frames = [df, df_3]
                        df = pd.concat(frames)
            plt.figure()
            seaborn.lineplot(x="Epochs", y="Loss", hue="Algorithm", markers=True, dashes=False, data=df)
            files = os.listdir(str(result))
            files_lwcase = [f.lower() for f in files]
            file_no = len([c for c in files_lwcase if d.lower() in c if 'training' in c])
            plt.savefig(str(result / (d + '_training_loss_plot_' + str(file_no) + '.pdf')), bbox_inches='tight', dpi=300)
//  [python]
def plot_mc_results(self,ax=None,figsize=(12,6)):
        """ Plots the results from a monte-carlo detector: the series' original values
        and the simulated lines.

        Args:
            ax (Axis): Optional. An existing axis to display the figure on.
            figsize (tuple): Default (12,6). The size of the resulting figure.
                Ignored if axis is not None.

        Returns:
            (Axis): The figure's axis.

        >>> from scalecast.AnomalyDetector import AnomalyDetector
        >>> from scalecast.SeriesTransformer import SeriesTransformer
        >>> from scalecast.Forecaster import Forecaster
        >>> import pandas_datareader as pdr
        >>> import matplotlib.pyplot as plt
        >>> df = pdr.get_data_fred('HOUSTNSA',start='1900-01-01',end='2021-06-01')
        >>> f = Forecaster(y=df['HOUSTNSA'],current_dates=df.index)
        >>> transformer = SeriesTransformer(f)
        >>> f = transformer.LogTransform()
        >>> f = transformer.DiffTransform(1)
        >>> f = transformer.DiffTransform(12)
        >>> detector = AnomalyDetector(f)
        >>> detector.MonteCarloDetect('2010-01-01','2020-12-01',cilevel=.99)
        >>> ax = f.plot_mc_results()
        >>> plt.show()
        """
        if ax is None:
            _, ax = plt.subplots(figsize=figsize)
        results = self.mc_results
        plt.plot(results["Date"], results["Actuals"], label="actuals", ax=ax)
        for c in results.iloc[:, 2:]:
            ax.plot(results["Date"], results[c], alpha=0.2)
        return ax
//  [python]
def plot_mc_results(self,ax=None,figsize=(12,6)):
        """ Plots the results from a monte-carlo detector: the series' original values
        and the simulated lines.

        Args:
            ax (Axis): Optional. An existing axis to display the figure on.
            figsize (tuple): Default (12,6). The size of the resulting figure.
                Ignored if axis is not None.

        Returns:
            (Axis): The figure's axis.

        >>> from scalecast.AnomalyDetector import AnomalyDetector
        >>> from scalecast.SeriesTransformer import SeriesTransformer
        >>> from scalecast.Forecaster import Forecaster
        >>> import pandas_datareader as pdr
        >>> import matplotlib.pyplot as plt
        >>> df = pdr.get_data_fred('HOUSTNSA',start='1900-01-01',end='2021-06-01')
        >>> f = Forecaster(y=df['HOUSTNSA'],current_dates=df.index)
        >>> transformer = SeriesTransformer(f)
        >>> f = transformer.LogTransform()
        >>> f = transformer.DiffTransform(1)
        >>> f = transformer.DiffTransform(12)
        >>> detector = AnomalyDetector(f)
        >>> detector.MonteCarloDetect('2010-01-01','2020-12-01',cilevel=.99)
        >>> ax = f.plot_mc_results()
        >>> plt.show()
        """
        if ax is None:
            _, ax = plt.subplots(figsize=figsize)
        results = self.mc_results
        sns.lineplot(x="Date", y="Actuals", data=results, label="actuals", ax=ax)
        for c in results.iloc[:, 2:]:
            ax.plot(results["Date"], results[c], alpha=0.2)
        return ax
//  [python]
def seaborn_line_histogram(in_file):
    try:
        # read csv file
        df = pd.read_csv(in_file)
        # pretty print of data
        print(tabulate(df.head(10), headers='keys', tablefmt='psql'))
        # group by state and output sequence is converted to dataframe
        df_mean = df.groupby(["jurisdiction"])["_1st_dose_allocations"].mean().reset_index()
        # rename column names of data frame
        df_mean.columns = ["state", "count_vaccine"]
        # sort descending by # vaccine dose 1
        df_mean_sorted = df_mean.sort_values(by=['count_vaccine'], ascending=False)
        # top 10 stats by largest mean
        df_mean_sorted_top10 = df_mean_sorted[0:10]
        # top 10 sorted mean print
        print(tabulate(df_mean_sorted_top10, headers='keys', tablefmt='psql'))
        ####################
        # LINE CHART PLOTTING
        ####################
        # line plot
        sns.pointplot(data=df_mean_sorted_top10, x="state", y="count_vaccine")
        # rotate x-axis labels
        plt.xticks(rotation=45)
        # alternate option without .gcf
        plt.subplots_adjust(left=0.2, bottom=0.25)
        # write to a file
        image_name = 'linediagram.eps'  # image name
        plt.savefig(image_name, format=image_format, dpi=1200)
        # show the actual plot
        plt.show()
        ###########################
        # HISTOGRAM CHART PLOTTING
        ###########################
        sns.set(font_scale=1.2)
        # plot histogram bars with top 10 states mean distribution count of vaccine
        p = sns.displot(df_mean_sorted_top10['count_vaccine'], kde=False)
        p.set_xlabels("count_vaccine", fontsize=30)
        p.set_ylabels("count", fontsize=30)
        plt.subplots_adjust(bottom=0.22)
        plt.xticks(rotation=90)
        # write to a file
        image_name = 'histogram.eps'  # image name
        plt.savefig(image_name, format=image_format, dpi=1200)
        plt.show()

    except Exception as e:
        traceback.print_exc()
//  [python]
def seaborn_line_histogram(in_file):
    try:
        # read csv file
        df = pd.read_csv(in_file)
        # pretty print of data
        print(tabulate(df.head(10), headers='keys', tablefmt='psql'))
        # group by state and output sequence is converted to dataframe
        df_mean = df.groupby(["jurisdiction"])["_1st_dose_allocations"].mean().reset_index()
        # rename column names of data frame
        df_mean.columns = ["state", "count_vaccine"]
        # sort descending by # vaccine dose 1
        df_mean_sorted = df_mean.sort_values(by=['count_vaccine'], ascending=False)
        # top 10 stats by largest mean
        df_mean_sorted_top10 = df_mean_sorted[0:10]
        # top 10 sorted mean print
        print(tabulate(df_mean_sorted_top10, headers='keys', tablefmt='psql'))
        ####################
        # LINE CHART PLOTTING
        ####################
        # line plot
        sns.lineplot(data=df_mean_sorted_top10, x="state", y="count_vaccine")
        # rotate x-axis labels
        plt.xticks(rotation=45)
        # alternate option without .gcf
        plt.subplots_adjust(left=0.2, bottom=0.25)
        # write to a file
        image_name = 'linediagram.eps'  # image name
        plt.savefig(image_name, format=image_format, dpi=1200)
        # show the actual plot
        plt.show()
        ###########################
        # HISTOGRAM CHART PLOTTING
        ###########################
        sns.set(font_scale=1.2)
        # plot histogram bars with top 10 states mean distribution count of vaccine
        p = sns.displot(df_mean_sorted_top10['count_vaccine'], kde=False)
        p.set_xlabels("count_vaccine", fontsize=30)
        p.set_ylabels("count", fontsize=30)
        plt.subplots_adjust(bottom=0.22)
        plt.xticks(rotation=90)
        # write to a file
        image_name = 'histogram.eps'  # image name
        plt.savefig(image_name, format=image_format, dpi=1200)
        plt.show()

    except Exception as e:
        traceback.print_exc()
//  [python]
def get_rolling_volume_per_exchange(
    data: pd.DataFrame,
    config: cconconf.Config,
    window: int,
    display_plot: bool = True,
) -> pd.DataFrame:
    """
    Compute rolling volume by exchange and plot them on graph.

    :param data: daily cumulative volume per exchange per currency pair
    :param config: config
    :param window: number of rolling windows
    :param display_plot: plot graph
    :return: rolling volume by exchange
    """
    volume = config["column_names"]["volume"]
    exchange_id = config["column_names"]["exchange"]
    data_grouped = data.groupby([exchange_id, "date"], as_index=False)
    volume_per_exchange_per_day = data_grouped[volume].sum()
    resampler = volume_per_exchange_per_day.groupby([exchange_id])
    rolling_volume = resampler[volume].transform(
        lambda x: x.rolling(window).mean()
    )
    volume_per_exchange_per_day = volume_per_exchange_per_day.merge(
        rolling_volume.to_frame(), left_index=True, right_index=True
    )
    volume_per_exchange_per_day.rename(
        columns={"volume_x": "volume", "volume_y": "rolling_volume"}, inplace=True
    )
    if display_plot:
        sns.tsplot(
            data=volume_per_exchange_per_day,
            time="date",
            value="rolling_volume",
            unit=exchange_id,
        )
    return volume_per_exchange_per_day
//  [python]
def get_rolling_volume_per_exchange(
    data: pd.DataFrame,
    config: cconconf.Config,
    window: int,
    display_plot: bool = True,
) -> pd.DataFrame:
    """
    Compute rolling volume by exchange and plot them on graph.

    :param data: daily cumulative volume per exchange per currency pair
    :param config: config
    :param window: number of rolling windows
    :param display_plot: plot graph
    :return: rolling volume by exchange
    """
    volume = config["column_names"]["volume"]
    exchange_id = config["column_names"]["exchange"]
    data_grouped = data.groupby([exchange_id, "date"], as_index=False)
    volume_per_exchange_per_day = data_grouped[volume].sum()
    resampler = volume_per_exchange_per_day.groupby([exchange_id])
    rolling_volume = resampler[volume].transform(
        lambda x: x.rolling(window).mean()
    )
    volume_per_exchange_per_day = volume_per_exchange_per_day.merge(
        rolling_volume.to_frame(), left_index=True, right_index=True
    )
    volume_per_exchange_per_day.rename(
        columns={"volume_x": "volume", "volume_y": "rolling_volume"}, inplace=True
    )
    if display_plot:
        sns.lineplot(
            data=volume_per_exchange_per_day,
            x="date",
            y="rolling_volume",
            hue=exchange_id,
        )
    return volume_per_exchange_per_day
//  [python]
def plot_score_calibration(
    file_format,
    preprocess_func,
    title,
    save_fname,
    skip_model_seeds={},
):
    models = [
        "EleutherAI/pythia-1b-deduped",
        "EleutherAI/pythia-2.8b-deduped",
        "EleutherAI/pythia-6.9b-deduped",
    ]
    colors = ["#8ac6e4", "#2b8cbe", "#08306b"]
    SEEDS = [44413, 55513, 66613, 77713]

    for model, color in zip(models, colors):
        margin_dfs = []
        for seed in SEEDS:
            if model in skip_model_seeds and seed in skip_model_seeds[model]:
                continue
            eval_fname = file_format.format(model=model, seed=seed)
            margin_df = preprocess_func(pd.read_csv(eval_fname))
            calibration_df = score_calibration(margin_df)
            margin_dfs.append(calibration_df)

        plt.errorbar(
            x=pd.concat(margin_dfs).reset_index()["middle"],
            y=pd.concat(margin_dfs).reset_index()["accuracy"],
            fmt='-',
            color=color,
            yerr=pd.concat(margin_dfs).reset_index()["accuracy"].std(),
        )

    perfect_calibration = margin_dfs[-1]["middle"].apply(
        lambda x: 1 / (1 + math.exp(-x))
    )
    plt.plot(
        margin_dfs[-1]["middle"],
        perfect_calibration,
        color="black",
        label="perfect calibration",
    )

    plt.title(title)
    plt.xlabel("Score difference")
    plt.ylabel("Accuracy")
    plt.gca().invert_yaxis()

    cmap = mcolors.ListedColormap(colors)
    norm = mcolors.BoundaryNorm(
        boundaries=[0, 1, 2, 3], ncolors=4
    )  # Adjust boundaries to match the number of colors
    cb = plt.colorbar(
        cm.ScalarMappable(norm=norm, cmap=cmap), ax=plt.gca(), orientation="vertical"
    )
    cb.set_ticks([0.5, 1.5, 2.5])
    cb.set_ticklabels(["1b", "2.8b", "6.9b"])
    cb.set_label("Parameters", rotation=270, labelpad=15)
    plt.legend(loc="lower right")

    plt.grid(True, which="both", ls="--", c="0.7")
    plt.tight_layout()
    plt.savefig(save_fname)
    plt.savefig(save_fname.replace("png", "pdf"))
    plt.clf()
    plt.close()
//  [python]
def plot_score_calibration(
    file_format,
    preprocess_func,
    title,
    save_fname,
    skip_model_seeds={},
):
    models = [
        "EleutherAI/pythia-1b-deduped",
        "EleutherAI/pythia-2.8b-deduped",
        "EleutherAI/pythia-6.9b-deduped",
    ]
    colors = ["#8ac6e4", "#2b8cbe", "#08306b"]
    SEEDS = [44413, 55513, 66613, 77713]

    for model, color in zip(models, colors):
        margin_dfs = []
        for seed in SEEDS:
            if model in skip_model_seeds and seed in skip_model_seeds[model]:
                continue
            eval_fname = file_format.format(model=model, seed=seed)
            margin_df = preprocess_func(pd.read_csv(eval_fname))
            calibration_df = score_calibration(margin_df)
            margin_dfs.append(calibration_df)

        sns.lineplot(
            data=pd.concat(margin_dfs).reset_index(),
            x="middle",
            y="accuracy",
            estimator="mean",
            errorbar="sd",
            color=color,
        )

    perfect_calibration = margin_dfs[-1]["middle"].apply(
        lambda x: 1 / (1 + math.exp(-x))
    )
    sns.lineplot(
        x=margin_dfs[-1]["middle"],
        y=perfect_calibration,
        color="black",
        label="perfect calibration",
    )

    plt.title(title)
    plt.xlabel("Score difference")
    plt.ylabel("Accuracy")
    plt.gca().invert_yaxis()

    cmap = mcolors.ListedColormap(colors)
    norm = mcolors.BoundaryNorm(
        boundaries=[0, 1, 2, 3], ncolors=4
    )  # Adjust boundaries to match the number of colors
    cb = plt.colorbar(
        cm.ScalarMappable(norm=norm, cmap=cmap), ax=plt.gca(), orientation="vertical"
    )
    cb.set_ticks([0.5, 1.5, 2.5])
    cb.set_ticklabels(["1b", "2.8b", "6.9b"])
    cb.set_label("Parameters", rotation=270, labelpad=15)
    plt.legend(loc="lower right")

    plt.grid(True, which="both", ls="--", c="0.7")
    plt.tight_layout()
    plt.savefig(save_fname)
    plt.savefig(save_fname.replace("png", "pdf"))
    plt.clf()
    plt.close()
//  [python]
def get_rolling_volume_per_coin(
    data: pd.DataFrame,
    config: cconconf.Config,
    window: int,
    display_plot: bool = True,
) -> pd.DataFrame:
    """
    Compute rolling volume by coins and plot them on graph.

    :param data: daily cumulative volume per exchange per currency pair
    :param config: config
    :param window: number of rolling windows
    :param display_plot: plot graph
    :return: rolling volume by coins
    """
    volume = config["column_names"]["volume"]
    currency_pair = config["column_names"]["currency_pair"]
    data_grouped = data.groupby([currency_pair, "date"], as_index=False)
    volume_per_coin_per_day = data_grouped[volume].sum()
    resampler = volume_per_coin_per_day.groupby([currency_pair])
    rolling_volume = resampler[volume].transform(
        lambda x: x.rolling(window).mean()
    )
    volume_per_coin_per_day = volume_per_coin_per_day.merge(
        rolling_volume.to_frame(), left_index=True, right_index=True
    )
    volume_per_coin_per_day.rename(
        columns={"volume_x": "volume", "volume_y": "rolling_volume"}, inplace=True
    )
    if display_plot:
        sns.tsplot(
            data=volume_per_coin_per_day,
            time="date",
            value="rolling_volume",
            unit=currency_pair,
        )
    return volume_per_coin_per_day
//  [python]
def get_rolling_volume_per_coin(
    data: pd.DataFrame,
    config: cconconf.Config,
    window: int,
    display_plot: bool = True,
) -> pd.DataFrame:
    """
    Compute rolling volume by coins and plot them on graph.

    :param data: daily cumulative volume per exchange per currency pair
    :param config: config
    :param window: number of rolling windows
    :param display_plot: plot graph
    :return: rolling volume by coins
    """
    volume = config["column_names"]["volume"]
    currency_pair = config["column_names"]["currency_pair"]
    data_grouped = data.groupby([currency_pair, "date"], as_index=False)
    volume_per_coin_per_day = data_grouped[volume].sum()
    resampler = volume_per_coin_per_day.groupby([currency_pair])
    rolling_volume = resampler[volume].transform(
        lambda x: x.rolling(window).mean()
    )
    volume_per_coin_per_day = volume_per_coin_per_day.merge(
        rolling_volume.to_frame(), left_index=True, right_index=True
    )
    volume_per_coin_per_day.rename(
        columns={"volume_x": "volume", "volume_y": "rolling_volume"}, inplace=True
    )
    if display_plot:
        sns.lineplot(
            data=volume_per_coin_per_day,
            x="date",
            y="rolling_volume",
            hue=currency_pair,
        )
    return volume_per_coin_per_day
//  [python]
for i, array in enumerate(arrays):
    arrays[i] = np.convolve(array, np.ones(window_size) / window_size, mode='valid')

plt.rcParams['figure.dpi'] = 300
array = np.array(arrays).T
df = pd.DataFrame(array, columns=range(len(arrays)))

sns.tsplot(data=df)
//  [python]
for i, array in enumerate(arrays):
    arrays[i] = np.convolve(array, np.ones(window_size) / window_size, mode='valid')

plt.rcParams['figure.dpi'] = 300
array = np.array(arrays).T
df = pd.DataFrame(array, columns=range(len(arrays)))

sns.lineplot(data=df)
//  [python]
def residual_diagnostic_plot(
    df,
    dist="norm",
    date_col="week",
    residual_col="residual",
    fitted_col="prediction",
    sparams=None,
):
    """
    Parameters
    ----------

    df : pd.DataFrame
    dist : str
    date_col : str
        column name of date
    residual_col : str
        column name of residual
    fitted_col: str
        column name of fitted value from model
    sparams : float or list
        extra parameters used in distribution such as t-dist

    Notes
    -----
    1. residual by time
    2. residual vs fitted
    3. residual histogram with vertical line as mean
    4. residuals qq plot
    5. residual ACF
    6. residual PACF
    """
    fig, ax = plt.subplots(3, 2, figsize=(15, 12))

    # plot 1 residual by time
    sns.pointplot(
        x=date_col,
        y=residual_col,
        data=df,
        ax=ax[0, 0],
        color=palette.OrbitPalette.BLUE.value,
        alpha=0.8,
        label="residual",
    )
    ax[0, 0].set_title("Residual by Time")
    ax[0, 0].legend()

    # plot 2 residual vs fitted
    sns.scatterplot(
        x=fitted_col,
        y=residual_col,
        data=df,
        ax=ax[0, 1],
        color=palette.OrbitPalette.BLUE.value,
        alpha=0.8,
        label="residual",
    )
    ax[0, 1].axhline(
        y=0,
        linestyle="--",
        color=palette.OrbitPalette.BLACK.value,
        alpha=0.5,
        label="0",
    )
    ax[0, 1].set_title("Residual vs Fitted")
    ax[0, 1].set_xlabel("fitted")
    ax[0, 1].legend()

    # plot 3 residual histogram with vertical line as mean
    sns.histplot(
        df[residual_col].values,
        kde=True,
        ax=ax[1, 0],
        color=palette.OrbitPalette.BLUE.value,
        label="residual",
        edgecolor="white",
        alpha=0.5,
        facecolor=palette.OrbitPalette.BLUE.value,
    )
    ax[1, 0].set_title("Residual Distribution")
    ax[1, 0].axvline(
        df[residual_col].mean(),
        color=palette.OrbitPalette.ORANGE.value,
        linestyle="--",
        alpha=0.9,
        label="residual mean",
    )
    ax[1, 0].set_ylabel("density")
    ax[1, 0].legend()

    # plot 4 residual qq plot
    if dist == "norm":
        _ = stats.probplot(df[residual_col].values, dist="norm", plot=ax[1, 1])
    elif dist == "t-dist":
        # t-dist qq-plot
        _ = stats.probplot(
            df[residual_col].values, dist=stats.t, sparams=sparams, plot=ax[1, 1]
        )

    # plot 5 residual ACF
    sm.graphics.tsa.plot_acf(
        df[residual_col].values,
        ax=ax[2, 0],
        title="Residual ACF",
        color=palette.OrbitPalette.BLUE.value,
    )
    ax[2, 0].set_xlabel("lag")
    ax[2, 0].set_ylabel("acf")

    # plot 6 residual PACF
    sm.graphics.tsa.plot_pacf(
        df[residual_col].values,
        ax=ax[2, 1],
        title="Residual PACF",
        color=palette.OrbitPalette.BLUE.value,
    )
    ax[2, 1].set_xlabel("lag")
    ax[2, 1].set_ylabel("pacf")
    fig.tight_layout()
//  [python]
def residual_diagnostic_plot(
    df,
    dist="norm",
    date_col="week",
    residual_col="residual",
    fitted_col="prediction",
    sparams=None,
):
    """
    Parameters
    ----------

    df : pd.DataFrame
    dist : str
    date_col : str
        column name of date
    residual_col : str
        column name of residual
    fitted_col: str
        column name of fitted value from model
    sparams : float or list
        extra parameters used in distribution such as t-dist

    Notes
    -----
    1. residual by time
    2. residual vs fitted
    3. residual histogram with vertical line as mean
    4. residuals qq plot
    5. residual ACF
    6. residual PACF
    """
    fig, ax = plt.subplots(3, 2, figsize=(15, 12))

    # plot 1 residual by time
    sns.lineplot(
        x=date_col,
        y=residual_col,
        data=df,
        ax=ax[0, 0],
        color=palette.OrbitPalette.BLUE.value,
        alpha=0.8,
        label="residual",
    )
    ax[0, 0].set_title("Residual by Time")
    ax[0, 0].legend()

    # plot 2 residual vs fitted
    sns.scatterplot(
        x=fitted_col,
        y=residual_col,
        data=df,
        ax=ax[0, 1],
        color=palette.OrbitPalette.BLUE.value,
        alpha=0.8,
        label="residual",
    )
    ax[0, 1].axhline(
        y=0,
        linestyle="--",
        color=palette.OrbitPalette.BLACK.value,
        alpha=0.5,
        label="0",
    )
    ax[0, 1].set_title("Residual vs Fitted")
    ax[0, 1].set_xlabel("fitted")
    ax[0, 1].legend()

    # plot 3 residual histogram with vertical line as mean
    sns.histplot(
        df[residual_col].values,
        kde=True,
        ax=ax[1, 0],
        color=palette.OrbitPalette.BLUE.value,
        label="residual",
        edgecolor="white",
        alpha=0.5,
        facecolor=palette.OrbitPalette.BLUE.value,
    )
    ax[1, 0].set_title("Residual Distribution")
    ax[1, 0].axvline(
        df[residual_col].mean(),
        color=palette.OrbitPalette.ORANGE.value,
        linestyle="--",
        alpha=0.9,
        label="residual mean",
    )
    ax[1, 0].set_ylabel("density")
    ax[1, 0].legend()

    # plot 4 residual qq plot
    if dist == "norm":
        _ = stats.probplot(df[residual_col].values, dist="norm", plot=ax[1, 1])
    elif dist == "t-dist":
        # t-dist qq-plot
        _ = stats.probplot(
            df[residual_col].values, dist=stats.t, sparams=sparams, plot=ax[1, 1]
        )

    # plot 5 residual ACF
    sm.graphics.tsa.plot_acf(
        df[residual_col].values,
        ax=ax[2, 0],
        title="Residual ACF",
        color=palette.OrbitPalette.BLUE.value,
    )
    ax[2, 0].set_xlabel("lag")
    ax[2, 0].set_ylabel("acf")

    # plot 6 residual PACF
    sm.graphics.tsa.plot_pacf(
        df[residual_col].values,
        ax=ax[2, 1],
        title="Residual PACF",
        color=palette.OrbitPalette.BLUE.value,
    )
    ax[2, 1].set_xlabel("lag")
    ax[2, 1].set_ylabel("pacf")
    fig.tight_layout()
//  [python]
f, ax = plt.subplots(figsize=(15, 10))
cmap = sns.diverging_palette(230, 20, as_cmap=True)
sns.heatmap(corr, mask=mask, cmap=cmap, center=0,
            square=True, linewidths=.5, cbar_kws={"shrink": .5}, annot=True, annot_kws={"fontsize":8})

#pivot table 
pd.pivot_table(data=df, values = 'var_1', index = 'var_2', columns = 'var_3')

#Line charts 
sns.pointplot(data = df, x = 'time_series_data', y= 'variable_name')
//  [python]
f, ax = plt.subplots(figsize=(15, 10))
cmap = sns.diverging_palette(230, 20, as_cmap=True)
sns.heatmap(corr, mask=mask, cmap=cmap, center=0,
            square=True, linewidths=.5, cbar_kws={"shrink": .5}, annot=True, annot_kws={"fontsize":8})

#pivot table 
pd.pivot_table(data=df, values = 'var_1', index = 'var_2', columns = 'var_3')

#Line charts 
sns.lineplot(data = df, x = 'time_series_data', y= 'variable_name')
//  [python]
def make_lineplots(df, ax):
    plot_df = df[["estimator","width", "n"]].groupby(["estimator","n"], group_keys=False).mean()["width"].reset_index()
    lplt = sns.pointplot(data=plot_df[plot_df["estimator"] != "imputed"], x="n", y="width", hue="estimator", ax=ax, hue_order=["prediction-powered", "classical"], join=True, markers="")
    ax.set_ylabel("width")
    ax.set_xlabel("n")
    ax.xaxis.set_tick_params()
    ax.yaxis.set_tick_params()
    ax.locator_params(tight=True, nbins=4)
    lplt.get_legend().remove()
    sns.despine(ax=ax,top=True,right=True)
//  [python]
def make_lineplots(df, ax):
    plot_df = df[["estimator","width", "n"]].groupby(["estimator","n"], group_keys=False).mean()["width"].reset_index()
    lplt = sns.lineplot(data=plot_df[plot_df["estimator"] != "imputed"], x="n", y="width", hue="estimator", ax=ax, hue_order=["prediction-powered", "classical"])
    ax.set_ylabel("width")
    ax.set_xlabel("n")
    ax.xaxis.set_tick_params()
    ax.yaxis.set_tick_params()
    ax.locator_params(tight=True, nbins=4)
    lplt.get_legend().remove()
    sns.despine(ax=ax,top=True,right=True)
//  [python]
def plot_accuracy(accs, threholds):
    sns.set(style="darkgrid")
    plt.figure(figsize=(8, 8))
    plt.xlabel("threshold")
    plt.ylabel("accuracy")
    plt.title("Accuracy")

    plt.plot(threholds, accs)
    plt.show()
//  [python]
def plot_accuracy(accs, threholds):
    sns.set(style="darkgrid")
    plt.figure(figsize=(8, 8))
    plt.xlabel("threshold")
    plt.ylabel("accuracy")
    plt.title("Accuracy")

    sns.lineplot(x="threshold", y="accuracy", data={"accuracy": accs, "threshold": threholds})
    plt.show()
//  [python]
def plot_roc(tpr, fpr, x_name="FPR", y_name="TPR"):
    sns.set(style="darkgrid")
    plt.figure(figsize=(8, 8))
    plt.xlabel(x_name)
    plt.ylabel(y_name)
    plt.title("ROC")

    plt.plot(fpr, tpr)
    plt.show()
//  [python]
def plot_roc(tpr, fpr, x_name="FPR", y_name="TPR"):
    sns.set(style="darkgrid")
    plt.figure(figsize=(8, 8))
    plt.xlabel(x_name)
    plt.ylabel(y_name)
    plt.title("ROC")

    sns.lineplot(x=x_name, y=y_name, data={x_name: fpr, y_name: tpr})
    plt.show()
//  [python]
def plot_seaborn(x, y, col_diff, diff_name, x_name, y_name):
    fig, ax = plt.subplots()
    if col_diff is None:
        d = {x_name: x, y_name: y}
        data = pd.DataFrame(data = d)
        
        sns.tsplot(x=x, y=y)
        plt.show() # SAVE TO PDF

    else:
        d = {x_name: x, y_name: y, diff_name: col_diff}
        data = pd.DataFrame(data = d)
        sns.tsplot(x=x, y=y, condition=col_diff, data=data, palette='Blues_r')
        handles, labels = ax.get_legend_handles_labels()
        ax.legend(handles=handles[1:], labels=labels[1:]) #, loc = 'upper right')
        
        ax.spines["top"].set_visible(False)
        ax.spines["right"].set_visible(False)
        plt.ylabel(new_y_name(y_name))
        plt.xlabel(x_name.capitalize())
        if SAVE:
            plt.savefig("neg_auc" + x_name + "_" + y_name + ".pdf", bbox_inches='tight')
//  [python]
def plot_seaborn(x, y, col_diff, diff_name, x_name, y_name):
    fig, ax = plt.subplots()
    if col_diff is None:
        d = {x_name: x, y_name: y}
        data = pd.DataFrame(data = d)
        
        sns.lineplot(x=x_name, y=y_name, data=data)
        plt.show() # SAVE TO PDF

    else:
        d = {x_name: x, y_name: y, diff_name: col_diff}
        data = pd.DataFrame(data = d)
        sns.lineplot(x=x_name, y=y_name, hue=diff_name, data=data, palette='Blues_r')
        handles, labels = ax.get_legend_handles_labels()
        ax.legend(handles=handles[1:], labels=labels[1:]) #, loc = 'upper right')
        
        ax.spines["top"].set_visible(False)
        ax.spines["right"].set_visible(False)
        plt.ylabel(new_y_name(y_name))
        plt.xlabel(x_name.capitalize())
        if SAVE:
            plt.savefig("neg_auc" + x_name + "_" + y_name + ".pdf", bbox_inches='tight')
//  [python]
d_names = df.dataset.unique()
N = d_names.shape[0]

fig, ax = plt.subplots(1, N)
# plot the results with time taken on y axis and sample size on x axis
fig.set_size_inches(6 * N, 6)
for i, d_name in enumerate(d_names):
    df_tmp = df[df["dataset"] == d_name]
    sns.pointplot(data=df_tmp, x="n_row", y="time_taken", hue="model", color="dataset", ax=ax[i])
    ax[i].set_title(d_name)
//  [python]
d_names = df.dataset.unique()
N = d_names.shape[0]

fig, ax = plt.subplots(1, N)
# plot the results with time taken on y axis and sample size on x axis
fig.set_size_inches(6 * N, 6)
for i, d_name in enumerate(d_names):
    df_tmp = df[df["dataset"] == d_name]
    sns.lineplot(data=df_tmp, x="n_row", y="time_taken", hue="model", color="dataset", ax=ax[i])
    ax[i].set_title(d_name)
//  [python]
def plot_prices(ax, mean_df, std_df):
    s.lineplot(x=mean_df.index, y='liquid_exchange_prices', data=mean_df, label='Liquid Exchange Prices', ax=ax, linewidth=2, color='blue')
    ax.fill_between(mean_df.index, mean_df['liquid_exchange_prices'] - std_df['liquid_exchange_prices'], mean_df['liquid_exchange_prices'] + std_df['liquid_exchange_prices'], color='blue', alpha=0.2)

    s.lineplot(x=mean_df.index, y='portfolio_prices', data=mean_df, label='Portfolio Prices', ax=ax, linewidth=2, color='orange')
    ax.fill_between(mean_df.index, mean_df['portfolio_prices'] - std_df['portfolio_prices'], mean_df['portfolio_prices'] + std_df['portfolio_prices'], color='orange', alpha=0.2)
    customize_plot(ax, 'Prices Over Time', 'Index', 'Price')
//  [python]
def plot_prices(ax, mean_df, std_df):
    sns.lineplot(x=mean_df.index, y='liquid_exchange_prices', data=mean_df, label='Liquid Exchange Prices', ax=ax, linewidth=2, color='blue')
    ax.fill_between(mean_df.index, mean_df['liquid_exchange_prices'] - std_df['liquid_exchange_prices'], mean_df['liquid_exchange_prices'] + std_df['liquid_exchange_prices'], color='blue', alpha=0.2)

    sns.lineplot(x=mean_df.index, y='portfolio_prices', data=mean_df, label='Portfolio Prices', ax=ax, linewidth=2, color='orange')
    ax.fill_between(mean_df.index, mean_df['portfolio_prices'] - std_df['portfolio_prices'], mean_df['portfolio_prices'] + std_df['portfolio_prices'], color='orange', alpha=0.2)
    customize_plot(ax, 'Prices Over Time', 'Index', 'Price')
//  [python]
def plot_portfolio_reserves(ax, mean_df, std_df):
    # Plot the balances
    ax.plot(mean_df.index, mean_df['portfolio_reserves_x'], label='Portfolio Reserves X', linewidth=2, alpha=0.5, color='blue')
    ax.fill_between(mean_df.index, mean_df['portfolio_reserves_x'] - std_df['portfolio_reserves_x'], mean_df['portfolio_reserves_x'] + std_df['portfolio_reserves_x'], color='blue', alpha=0.1)
    ax.plot(mean_df.index, mean_df['portfolio_reserves_y'], label='Portfolio Reserves Y', linewidth=2, alpha=0.5, color='orange')
    ax.fill_between(mean_df.index, mean_df['portfolio_reserves_y'] - std_df['portfolio_reserves_y'], mean_df['portfolio_reserves_y'] + std_df['portfolio_reserves_y'], color='orange', alpha=0.1)

    customize_plot(ax, 'Portfolio Reserves Over Time', 'Index', 'Value in WAD')
//  [python]
def plot_portfolio_reserves(ax, mean_df, std_df):
    # Plot the balances
    sns.lineplot(x=mean_df.index, y='portfolio_reserves_x', data=mean_df, label='Portfolio Reserves X', ax=ax, linewidth=2, alpha=0.5, legend=False, color='blue')
    ax.fill_between(mean_df.index, mean_df['portfolio_reserves_x'] - std_df['portfolio_reserves_x'], mean_df['portfolio_reserves_x'] + std_df['portfolio_reserves_x'], color='blue', alpha=0.1)
    sns.lineplot(x=mean_df.index, y='portfolio_reserves_y', data=mean_df, label='Portfolio Reserves Y', ax=ax, linewidth=2, alpha=0.5, legend=False, color='orange')
    ax.fill_between(mean_df.index, mean_df['portfolio_reserves_y'] - std_df['portfolio_reserves_y'], mean_df['portfolio_reserves_y'] + std_df['portfolio_reserves_y'], color='orange', alpha=0.1)

    customize_plot(ax, 'Portfolio Reserves Over Time', 'Index', 'Value in WAD')
//  [python]
def plot_lp_portfolio_values(ax, mean_df, std_df):
    ax.plot(mean_df.index, mean_df['lp_portfolio_value'], label='Portfolio Value', linewidth=2, alpha=1, color='purple')
    ax.fill_between(mean_df.index, mean_df['lp_portfolio_value'] - std_df['lp_portfolio_value'], mean_df['lp_portfolio_value'] + std_df['lp_portfolio_value'], color='purple', alpha=0.3)
    customize_plot(ax, 'LP Portfolio Values Over Time', 'Index', 'Value in WAD')
//  [python]
def plot_lp_portfolio_values(ax, mean_df, std_df):
    sns.lineplot(x=mean_df.index, y='lp_portfolio_value', data=mean_df, label='Portfolio Value', ax=ax, linewidth=2, alpha=1, legend=False, color='purple')
    ax.fill_between(mean_df.index, mean_df['lp_portfolio_value'] - std_df['lp_portfolio_value'], mean_df['lp_portfolio_value'] + std_df['lp_portfolio_value'], color='purple', alpha=0.3)
    customize_plot(ax, 'LP Portfolio Values Over Time', 'Index', 'Value in WAD')
//  [python]
def plot_arbitrageur_balances_and_values(ax, df):
    # Plot the balances
    s.lineplot(x=df.index, y='arbitrageur_relative_balances_x', data=df, label='Relative Arbitrageur Balances X', ax=ax, linewidth=2, alpha=0.5, legend=False)
    s.lineplot(x=df.index, y='arbitrageur_relative_balances_y', data=df, label='Relative Arbitrageur Balances Y', ax=ax, linewidth=2, alpha=0.5, legend=False)

    # Create a second y-axis to plot the portfolio value
    ax2 = ax.twinx()
    s.lineplot(x=df.index, y='arbitrageur_portfolio_value', data=df, label='Arbitrageur Portfolio Value', ax=ax2, linewidth=2, color='purple', legend=False)

    # Customize the plot
    ax.set_title('Arbitrageur Balances and Portfolio Values Over Time', fontsize=16)
    ax.set_xlabel('Index', fontsize=14)
    ax.set_ylabel('Balance in WAD', fontsize=14)
    ax.grid(True)

    ax2.set_ylabel('Portfolio Value in WAD', fontsize=14)

    # Combine legends from both axes
    lines, labels = ax.get_legend_handles_labels()
    lines2, labels2 = ax2.get_legend_handles_labels()
    ax2.legend(lines + lines2, labels + labels2, loc=0, fontsize=12)