jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def plot_data(data, value="AverageReturn"):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    import IPython; IPython.embed()
    sns.set(style="darkgrid", font_scale=1)
    sns.tsplot(data=data, time="Iteration", value=value, unit="Unit", condition="Condition", linewidth=1, estimator=rolling_mean)
    plt.legend(loc='best').draggable()
//  [python]
def plot_data(data, value="AverageReturn"):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    import IPython; IPython.embed()
    sns.set(style="darkgrid", font_scale=1)
    sns.lineplot(data=data, x="Iteration", y=value, hue="Condition", units="Unit", estimator=rolling_mean, linewidth=1)
    plt.legend(loc='best').draggable()
//  [python]
def plot_score_vs_n_evals(xvals, yvals, algo, color):
    ax = sns.tsplot(yvals, xvals, ci=90, condition=algo, color=color)
    ax.set_xlim(-xvals[-1] * 0.03, )
    plt.xlabel('Number of evaluations', fontsize=14)
    plt.ylabel('Rewards', fontsize=14)
    plt.legend(fontsize=14)
//  [python]
def plot_score_vs_n_evals(xvals, yvals, algo, color):
    ax = sns.lineplot(x=xvals, y=yvals, ci=90, label=algo, color=color)
    ax.set_xlim(-xvals[-1] * 0.03, )
    plt.xlabel('Number of evaluations', fontsize=14)
    plt.ylabel('Rewards', fontsize=14)
    plt.legend(fontsize=14)
//  [python]
def plot_ppo_run(name, sparse=False, limit=None, print_config=False, seeds=None, single=False):
    from collections import defaultdict
    train_infos, config = load_training_data(name, seeds)
    
    if print_config:
        print(config)
    
    if limit is None:
        limit = config["PPO_RUN_TOT_TIMESTEPS"]
    
    num_datapoints = len(train_infos[0]['eprewmean'])
    
    prop_data = limit / config["PPO_RUN_TOT_TIMESTEPS"]
    ciel_data_idx = int(num_datapoints * prop_data)

    datas = []
    for seed_num, info in enumerate(train_infos):
        info['xs'] = config["TOTAL_BATCH_SIZE"] * np.array(range(1, ciel_data_idx + 1))
        if single:
            plt.plot(info['xs'], info["ep_sparse_rew_mean"][:ciel_data_idx], alpha=1, label="Sparse{}".format(seed_num))
        datas.append(info["ep_sparse_rew_mean"][:ciel_data_idx])
    if not single:
        seaborn.tsplot(time=info['xs'], data=datas)
    plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
    
    if single:
        plt.legend()
//  [python]
def plot_ppo_run(name, sparse=False, limit=None, print_config=False, seeds=None, single=False):
    from collections import defaultdict
    train_infos, config = load_training_data(name, seeds)
    
    if print_config:
        print(config)
    
    if limit is None:
        limit = config["PPO_RUN_TOT_TIMESTEPS"]
    
    num_datapoints = len(train_infos[0]['eprewmean'])
    
    prop_data = limit / config["PPO_RUN_TOT_TIMESTEPS"]
    ciel_data_idx = int(num_datapoints * prop_data)

    datas = []
    for seed_num, info in enumerate(train_infos):
        info['xs'] = config["TOTAL_BATCH_SIZE"] * np.array(range(1, ciel_data_idx + 1))
        if single:
            plt.plot(info['xs'], info["ep_sparse_rew_mean"][:ciel_data_idx], alpha=1, label="Sparse{}".format(seed_num))
        datas.append(info["ep_sparse_rew_mean"][:ciel_data_idx])
    if not single:
        seaborn.lineplot(x=info['xs'], y=datas)
    plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
    
    if single:
        plt.legend()
//  [python]
def plot_penalty_example(penalty):
    """
    Show the penalty function for genuine and impostor users
    """
    genuine_idx = penalty['reference_user'] == penalty['query_user']
    genuine = penalty[genuine_idx]
    impostor = penalty[~genuine_idx]
    thresh = genuine['penalty'].max()
    impostor.loc[:, 'type'] = 'Impostor'

    sns.set(style='darkgrid')
    sns.set_context('notebook', font_scale=3.0)
    plt.figure(figsize=(16, 10))

    g = sns.tsplot(impostor, time='event_idx', unit='reference_user', condition='type', value='penalty',
                   color='cubehelix', ci=95)
    g.set_xlabel('Event')
    g.set_ylabel('Penalty')
    plt.plot(genuine['event_idx'], genuine['penalty'], label='Genuine')
    plt.axhline(thresh, linestyle='--', color='k', label='Threshold')
    plt.legend(title=None, loc='lower right')
    plt.xticks(np.linspace(0, 500, 6))
    return
//  [python]
def plot_penalty_example(penalty):
    """
    Show the penalty function for genuine and impostor users
    """
    genuine_idx = penalty['reference_user'] == penalty['query_user']
    genuine = penalty[genuine_idx]
    impostor = penalty[~genuine_idx]
    thresh = genuine['penalty'].max()
    impostor.loc[:, 'type'] = 'Impostor'

    sns.set(style='darkgrid')
    sns.set_context('notebook', font_scale=3.0)
    plt.figure(figsize=(16, 10))

    g = sns.lineplot(x='event_idx', y='penalty', hue='type', data=impostor, ci=95)
    g.set_xlabel('Event')
    g.set_ylabel('Penalty')
    plt.plot(genuine['event_idx'], genuine['penalty'], label='Genuine')
    plt.axhline(thresh, linestyle='--', color='k', label='Threshold')
    plt.legend(title=None, loc='lower right')
    plt.xticks(np.linspace(0, 500, 6))
    return
//  [python]
def plot_error(roc):
    """
    Plot far and frr as a function of threshold
    """
    roc = roc.copy()

    min_thresh, max_thresh = roc['threshold'].min(), roc['threshold'].max()

    far = roc[['fold', 'threshold', 'far']]
    far.columns = ['fold', 'threshold', 'value']
    far['Error'] = 'FAR'

    frr = roc[['fold', 'threshold', 'frr']]
    frr.columns = ['fold', 'threshold', 'value']
    frr['Error'] = 'FRR'

    roc = pd.DataFrame(pd.concat([frr, far]))

    sns.set(style='darkgrid')
    sns.set_context('notebook', font_scale=3.0)
    plt.figure(figsize=(8, 6))

    g = sns.tsplot(roc, time='threshold', unit='fold', condition='Error', value='value', color='cubehelix', ci=95)
    g.set_xlabel('Threshold')
    g.set_ylabel('Error')
    g.set_xlim(min_thresh, max_thresh)
    g.set_ylim(0, 1)
    plt.legend(title=None, loc='lower left')
    return
//  [python]
def plot_error(roc):
    """
    Plot far and frr as a function of threshold
    """
    roc = roc.copy()

    min_thresh, max_thresh = roc['threshold'].min(), roc['threshold'].max()

    far = roc[['fold', 'threshold', 'far']]
    far.columns = ['fold', 'threshold', 'value']
    far['Error'] = 'FAR'

    frr = roc[['fold', 'threshold', 'frr']]
    frr.columns = ['fold', 'threshold', 'value']
    frr['Error'] = 'FRR'

    roc = pd.DataFrame(pd.concat([frr, far]))

    sns.set(style='darkgrid')
    sns.set_context('notebook', font_scale=3.0)
    plt.figure(figsize=(8, 6))

    g = sns.lineplot(data=roc, x='threshold', y='value', hue='Error', units='fold', estimator=None, ci=95)
    g.set_xlabel('Threshold')
    g.set_ylabel('Error')
    g.set_xlim(min_thresh, max_thresh)
    g.set_ylim(0, 1)
    plt.legend(title=None, loc='lower left')
    return
//  [python]
def plot_roc(roc, condition, pivot):
    """
    Plot an roc curve with confidence bands
    """
    # Interpolate to get tpr for each fpr
    far = np.linspace(0, 1, 1000)

    def _interp(df):
        df = pd.DataFrame({'far': far, 'frr': interp(far[::-1], df['far'][::-1], df['frr'][::-1])[::-1]})
        return df

    if type(roc) == list:
        rocs = []
        for name, r in roc:
            r = r.groupby(pivot).apply(_interp).reset_index(level=1, drop=True).reset_index()
            r[condition] = name
            rocs.append(r)
        roc = pd.concat(rocs)
    else:
        roc = roc.groupby(pivot).apply(_interp).reset_index(level=1, drop=True).reset_index()

    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_subplot(111, aspect='equal')
    g = sns.tsplot(roc, time='far', unit=pivot, condition=condition, value='frr', ci=95)
    g.set_xlabel('False acceptance rate')
    g.set_ylabel('False rejection rate')
    g.set_xlim(0, 1)
    g.set_ylim(0, 1)
    plt.legend(title=None)
    return
//  [python]
def plot_roc(roc, condition, pivot):
    """
    Plot an roc curve with confidence bands
    """
    # Interpolate to get tpr for each fpr
    far = np.linspace(0, 1, 1000)

    def _interp(df):
        df = pd.DataFrame({'far': far, 'frr': interp(far[::-1], df['far'][::-1], df['frr'][::-1])[::-1]})
        return df

    if type(roc) == list:
        rocs = []
        for name, r in roc:
            r = r.groupby(pivot).apply(_interp).reset_index(level=1, drop=True).reset_index()
            r[condition] = name
            rocs.append(r)
        roc = pd.concat(rocs)
    else:
        roc = roc.groupby(pivot).apply(_interp).reset_index(level=1, drop=True).reset_index()

    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_subplot(111, aspect='equal')
    g = sns.lineplot(data=roc, x='far', y='frr', hue=condition, ci=95, units=pivot)
    g.set_xlabel('False acceptance rate')
    g.set_ylabel('False rejection rate')
    g.set_xlim(0, 1)
    g.set_ylim(0, 1)
    plt.legend(title=None)
    return
//  [python]
def plotTraining(folded_results,method,loss,save_directory):
    fold_counter = 0
    datadict = {"epochs": np.arange(0, len(folded_results[0][method]["history"]["loss"])).tolist()}
    collist = []
    for fold in folded_results:
        results = fold[method]
        history = results["history"]
        collist.append(f"fold_{fold_counter}")
        if loss:
            datadict[f"fold_{fold_counter}"] = history["loss"]
        fold_counter += 1
    df = pd.DataFrame(datadict ,columns=["epochs"]+collist)
    df = df.set_index(df.epochs)
    columns = [df[col] for col in collist]
    sns_plot = sns.tsplot(columns, color="indianred")
    fig = sns_plot.get_figure()
    if loss:
        fig.savefig(f"{save_directory}/{method}_loss.pdf")
    else:
        fig.savefig(f"{save_directory}/{method}_acc.pdf")
    plt.clf()
//  [python]
def plotTraining(folded_results,method,loss,save_directory):
    fold_counter = 0
    datadict = {"epochs": np.arange(0, len(folded_results[0][method]["history"]["loss"])).tolist()}
    collist = []
    for fold in folded_results:
        results = fold[method]
        history = results["history"]
        collist.append(f"fold_{fold_counter}")
        if loss:
            datadict[f"fold_{fold_counter}"] = history["loss"]
        fold_counter += 1
    df = pd.DataFrame(datadict ,columns=["epochs"]+collist)
    df = df.set_index(df.epochs)
    df_long = pd.melt(df.reset_index(), id_vars=['epochs'], var_name='fold', value_name='value')
    sns_plot = sns.lineplot(x="epochs", y="value", hue="fold", data=df_long, color="indianred")
    fig = sns_plot.get_figure()
    if loss:
        fig.savefig(f"{save_directory}/{method}_loss.pdf")
    else:
        fig.savefig(f"{save_directory}/{method}_acc.pdf")
    plt.clf()
//  [python]
def plotResults(datasets, results, save_directory, k_folds):
    # need df with row: <dataset,method,fold,value> then
    # sns.lineplot(data=df,x="dataset",y="value",style="method)
    x_axis = {"datasets": datasets}
    y_series = dict()
    methods = results[datasets[0]][0].keys()
    for method in methods:
        y_series[method] = dict()
        y_series[method]["datasets"] = datasets
        for i in range(0, k_folds):
            y_series[method][f"{method}_{i}fold"] = list()
    for dataset in datasets:
        folded_results = results[dataset]
        fold_counter = 0
        for fold in folded_results:
            for method in fold:
                res_loss = fold[method]["res_loss"]
                y_series[method][f"{method}_{fold_counter}fold"].append(res_loss)
            fold_counter += 1
            #collist.append(f"fold_{fold_counter}")
    fig, ax = plt.subplots()
    for method in methods:
        collist = [f"{method}_{fold}fold" for fold in range(0, k_folds)]
        df = pd.DataFrame(y_series[method], columns=["datasets"]+collist)
        df = df.set_index(df.datasets)
        columns = [df[col] for col in collist]
        sns_plot = sns.tsplot(columns, ax=ax)
        fig = sns_plot.get_figure()
    fig.savefig(f"{save_directory}/all_methods_loss.pdf")
//  [python]
def plotResults(datasets, results, save_directory, k_folds):
    x_axis = {"datasets": datasets}
    y_series = dict()
    methods = results[datasets[0]][0].keys()
    for method in methods:
        y_series[method] = dict()
        y_series[method]["datasets"] = datasets
        for i in range(0, k_folds):
            y_series[method][f"{method}_{i}fold"] = list()
    for dataset in datasets:
        folded_results = results[dataset]
        fold_counter = 0
        for fold in folded_results:
            for method in fold:
                res_loss = fold[method]["res_loss"]
                y_series[method][f"{method}_{fold_counter}fold"].append(res_loss)
            fold_counter += 1
    fig, ax = plt.subplots()
    for method in methods:
        collist = [f"{method}_{fold}fold" for fold in range(0, k_folds)]
        df = pd.DataFrame(y_series[method], columns=["datasets"]+collist)
        df = df.melt(id_vars="datasets", var_name="fold", value_name="res_loss")
        sns_plot = sns.lineplot(data=df, x="datasets", y="res_loss", hue="fold", ax=ax)
        fig = sns_plot.get_figure()
    fig.savefig(f"{save_directory}/all_methods_loss.pdf")
//  [python]
def plot_learn_curve(xvals, vals, algo, color):
    ax = sns.tsplot(vals, xvals, ci=90, condition=algo, color=color)
    ax.set_xlim(0, )
    # ax.set_xticklabels(xvals)
    plt.xlabel('Portions of N',fontsize=14)
    plt.ylabel('Rewards',fontsize=14)
    plt.legend(fontsize=14)
//  [python]
def plot_learn_curve(xvals, vals, algo, color):
    ax = sns.lineplot(x=xvals, y=vals, ci=90, label=algo, color=color)
    ax.set_xlim(0, )
    # ax.set_xticklabels(xvals)
    plt.xlabel('Portions of N',fontsize=14)
    plt.ylabel('Rewards',fontsize=14)
    plt.legend(fontsize=14)
//  [python]
def plot( self):
		sns.tsplot(data=self.pdo, time="alpha", unit="unit", condition="Method", value="r2")
		plt.xscale('log')
		plt.ylabel( r'$r^2$')
//  [python]
def plot( self):
		sns.lineplot(data=self.pdo, x="alpha", y="r2", hue="Method", units="unit")
		plt.xscale('log')
		plt.ylabel( r'$r^2$')
//  [python]
def plot_time_series(combined_exp_dfs, title):
    sns.tsplot(data=combined_exp_dfs, value="fitness", condition="condition", unit="run", time="gen")
    plt.title(title)
    plt.savefig("{}.pdf".format(title))
//  [python]
def plot_time_series(combined_exp_dfs, title):
    sns.lineplot(data=combined_exp_dfs, x="gen", y="fitness", hue="condition", units="run")
    plt.title(title)
    plt.savefig("{}.pdf".format(title))
//  [python]
def timeseries(df, time, y, filename=None):
    p = sns.tsplot(data=df, time=time, value=y)
    plt.show()
//  [python]
def timeseries(df, time, y, filename=None):
    p = sns.lineplot(data=df, x=time, y=y)
    plt.show()
//  [python]
h = 10
d = 100
plt.figure(figsize=(w, h), dpi=d)


# plt.ticklabel_format(style='plain', axis='x',useOffset=False)
sns.set(style="darkgrid", font_scale=1.5)
ax = sns.tsplot(data=guardRewards, time=ckpts, color='green', ci='sd', linewidth=4)
//  [python]
h = 10
d = 100
plt.figure(figsize=(w, h), dpi=d)


# plt.ticklabel_format(style='plain', axis='x',useOffset=False)
sns.set(style="darkgrid", font_scale=1.5)
ax = sns.lineplot(data=guardRewards, x=ckpts, y='value', color='green', ci='sd', linewidth=4)
//  [python]
def plot_irfs(self, filename_stub='figures/irf_{}.pdf'):
        """This function plots the IRFs. 

        Args: 

        """        
        shock_name='Productivity'
        for (key_p, val_p), (key_n, val_n)  in zip(self.irf_dict_p.items(), self.irf_dict_n.items()):

            irf_p = val_p[0]
            irf_n = val_n[0]
            change_str = val_p[1]        

            fig, ax = plt.subplots(1,1, figsize=(6, 5))
            sns.tsplot(irf_p, color='blue', linestyle='dashed', ax=ax)
            sns.tsplot(irf_n, color='red', linestyle='solid', ax=ax)

            title = '{} Change from {} Standard Deviation Shock to {}'.format(change_str, self.shock_size, shock_name)
            ax.set_xlabel('Months')
            ax.set_ylabel(key_p)
            ax.set_title(title)
            ax.legend(['Pos shock', 'Neg shock'], ncol=2)

            if filename_stub is None:
                plt.show()
            else:
                filename = filename_stub.format(key_p)
                fig.savefig(filename)
//  [python]
def plot_irfs(self, filename_stub='figures/irf_{}.pdf'):
        """This function plots the IRFs. 

        Args: 

        """        
        shock_name='Productivity'
        for (key_p, val_p), (key_n, val_n)  in zip(self.irf_dict_p.items(), self.irf_dict_n.items()):

            irf_p = val_p[0]
            irf_n = val_n[0]
            change_str = val_p[1]        

            fig, ax = plt.subplots(1,1, figsize=(6, 5))
            sns.lineplot(data=irf_p, color='blue', linestyle='dashed', ax=ax)
            sns.lineplot(data=irf_n, color='red', linestyle='solid', ax=ax)

            title = '{} Change from {} Standard Deviation Shock to {}'.format(change_str, self.shock_size, shock_name)
            ax.set_xlabel('Months')
            ax.set_ylabel(key_p)
            ax.set_title(title)
            ax.legend(['Pos shock', 'Neg shock'], ncol=2)

            if filename_stub is None:
                plt.show()
            else:
                filename = filename_stub.format(key_p)
                fig.savefig(filename)
//  [python]
def plot_pbt_runs(pbt_model_paths, seeds, single=False, save=False, show=False):
    """Plots sparse rewards"""
    for layout in pbt_model_paths.keys():
        logs_and_cfgs = get_logs(pbt_model_paths[layout], seeds=seeds)
        log, cfg = logs_and_cfgs[0]

        ep_rew_means = []
        for l, cfg in logs_and_cfgs:
            rews = np.array(l['ep_sparse_rew_mean'])
            ep_rew_means.append(rews)
        ep_rew_means = np.array(ep_rew_means)

        ppo_updates_per_pairing = int(cfg['PPO_RUN_TOT_TIMESTEPS'] / cfg['TOTAL_BATCH_SIZE'])
        x_axis = list(range(0, log['num_ppo_runs'] * cfg['PPO_RUN_TOT_TIMESTEPS'], cfg['PPO_RUN_TOT_TIMESTEPS'] // ppo_updates_per_pairing))
        plt.figure(figsize=(7,4.5))
        if single:
            for i in range(len(logs_and_cfgs)):
                plt.plot(x_axis, ep_rew_means[i], label=str(i))
            plt.legend()
        else:
            seaborn.tsplot(time=x_axis, data=ep_rew_means)
        plt.xlabel("Environment timesteps")
        plt.ylabel("Mean episode reward")
        plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
        plt.tight_layout()
        if save: plt.savefig("rew_pbt_" + layout, bbox_inches='tight')
        if show: plt.show()
//  [python]
def plot_pbt_runs(pbt_model_paths, seeds, single=False, save=False, show=False):
    """Plots sparse rewards"""
    for layout in pbt_model_paths.keys():
        logs_and_cfgs = get_logs(pbt_model_paths[layout], seeds=seeds)
        log, cfg = logs_and_cfgs[0]

        ep_rew_means = []
        for l, cfg in logs_and_cfgs:
            rews = np.array(l['ep_sparse_rew_mean'])
            ep_rew_means.append(rews)
        ep_rew_means = np.array(ep_rew_means)

        ppo_updates_per_pairing = int(cfg['PPO_RUN_TOT_TIMESTEPS'] / cfg['TOTAL_BATCH_SIZE'])
        x_axis = list(range(0, log['num_ppo_runs'] * cfg['PPO_RUN_TOT_TIMESTEPS'], cfg['PPO_RUN_TOT_TIMESTEPS'] // ppo_updates_per_pairing))
        plt.figure(figsize=(7,4.5))
        if single:
            for i in range(len(logs_and_cfgs)):
                plt.plot(x_axis, ep_rew_means[i], label=str(i))
            plt.legend()
        else:
            seaborn.lineplot(x=x_axis, y=ep_rew_means)
        plt.xlabel("Environment timesteps")
        plt.ylabel("Mean episode reward")
        plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
        plt.tight_layout()
        if save: plt.savefig("rew_pbt_" + layout, bbox_inches='tight')
        if show: plt.show()
//  [python]
def plot_pbt_runs(pbt_model_paths, seeds, single=False, save=False, show=False):
    """Plots sparse rewards"""
    for layout in pbt_model_paths.keys():
        try:
            logs_and_cfgs = get_logs(pbt_model_paths[layout], seeds=seeds)
            log, cfg = logs_and_cfgs[0]

            ep_rew_means = []
            for l, cfg in logs_and_cfgs:
                rews = np.array(l['ep_sparse_rew_mean'])
                ep_rew_means.append(rews)
            ep_rew_means = np.array(ep_rew_means)

            ppo_updates_per_pairing = int(cfg['PPO_RUN_TOT_TIMESTEPS'] / cfg['TOTAL_BATCH_SIZE'])
            x_axis = list(range(0, log['num_ppo_runs'] * cfg['PPO_RUN_TOT_TIMESTEPS'], cfg['PPO_RUN_TOT_TIMESTEPS'] // ppo_updates_per_pairing))
            plt.figure(figsize=(7,4.5))
            if single:
                for i in range(len(logs_and_cfgs)):
                    plt.plot(x_axis, ep_rew_means[i], label=str(i))
                plt.legend()
            else:
                seaborn.tsplot(time=x_axis, data=ep_rew_means)
            plt.xlabel("Environment timesteps")
            plt.ylabel("Mean episode reward")
            plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
            plt.tight_layout()
            if save: plt.savefig("rew_pbt_" + layout, bbox_inches='tight')
            if show: plt.show()
        except:
            continue
//  [python]
def plot_pbt_runs(pbt_model_paths, seeds, single=False, save=False, show=False):
    """Plots sparse rewards"""
    for layout in pbt_model_paths.keys():
        try:
            logs_and_cfgs = get_logs(pbt_model_paths[layout], seeds=seeds)
            log, cfg = logs_and_cfgs[0]

            ep_rew_means = []
            for l, cfg in logs_and_cfgs:
                rews = np.array(l['ep_sparse_rew_mean'])
                ep_rew_means.append(rews)
            ep_rew_means = np.array(ep_rew_means)

            ppo_updates_per_pairing = int(cfg['PPO_RUN_TOT_TIMESTEPS'] / cfg['TOTAL_BATCH_SIZE'])
            x_axis = list(range(0, log['num_ppo_runs'] * cfg['PPO_RUN_TOT_TIMESTEPS'], cfg['PPO_RUN_TOT_TIMESTEPS'] // ppo_updates_per_pairing))
            plt.figure(figsize=(7,4.5))
            if single:
                for i in range(len(logs_and_cfgs)):
                    plt.plot(x_axis, ep_rew_means[i], label=str(i))
                plt.legend()
            else:
                seaborn.lineplot(x=x_axis, y=ep_rew_means)
            plt.xlabel("Environment timesteps")
            plt.ylabel("Mean episode reward")
            plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
            plt.tight_layout()
            if save: plt.savefig("rew_pbt_" + layout, bbox_inches='tight')
            if show: plt.show()
        except:
            continue
//  [python]
def plot_with_std(tree,
                  tag_sets,
                  title="TODO",
                  y_axis="TODO",
                  verbose=False,
                  x_axis_label="# iterations",
                  **kwargs):
    data = []
    steps = None
    min_runs_num = np.inf
    min_steps_num = np.inf
    max_runs_num = 0
    max_steps_num = 0
    for tags in tag_sets:
        series = tree.get(tags)
        steps = series[0, 0, :]
        values = series[:, 1, :]
        data.append(values)
        min_runs_num = min(min_runs_num, values.shape[0])
        min_steps_num = min(min_steps_num, values.shape[1])
        max_runs_num = max(max_runs_num, values.shape[0])
        max_steps_num = max(max_steps_num, values.shape[1])

    if verbose:
        if min_steps_num != max_steps_num:
            # TODO
            pass
        if min_runs_num != max_runs_num:
            # TODO
            pass

    steps = steps[0:min_steps_num]
    # TODO it's a workaround for different number of runs and points
    if len(data) > 1:
        data = [d[0:min_runs_num, 0:min_steps_num] for d in data]
        data = np.stack(data, axis=2)
        tag_sets = [t[-1] for t in tag_sets]
    else:
        tag_sets = None
        data = data[0]
    default_kwargs = {
        "err_style": "ci_band",
        "ci": "sd",
    }
    default_kwargs.update(kwargs)
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        sns.tsplot(data,
                   time=steps,
                   value=y_axis,
                   condition=tag_sets,
                   legend=len(data.shape) > 2,
                   **default_kwargs
                   )
    plt.title(title)
    plt.xlabel(x_axis_label)
//  [python]
def plot_with_std(tree,
                  tag_sets,
                  title="TODO",
                  y_axis="TODO",
                  verbose=False,
                  x_axis_label="# iterations",
                  **kwargs):
    data = []
    steps = None
    min_runs_num = np.inf
    min_steps_num = np.inf
    max_runs_num = 0
    max_steps_num = 0
    for tags in tag_sets:
        series = tree.get(tags)
        steps = series[0, 0, :]
        values = series[:, 1, :]
        data.append(values)
        min_runs_num = min(min_runs_num, values.shape[0])
        min_steps_num = min(min_steps_num, values.shape[1])
        max_runs_num = max(max_runs_num, values.shape[0])
        max_steps_num = max(max_steps_num, values.shape[1])

    if verbose:
        if min_steps_num != max_steps_num:
            # TODO
            pass
        if min_runs_num != max_runs_num:
            # TODO
            pass

    steps = steps[0:min_steps_num]
    # TODO it's a workaround for different number of runs and points
    if len(data) > 1:
        data = [d[0:min_runs_num, 0:min_steps_num] for d in data]
        data = np.stack(data, axis=2)
        tag_sets = [t[-1] for t in tag_sets]
    else:
        tag_sets = None
        data = data[0]
    default_kwargs = {
        "err_style": "ci_band",
        "ci": "sd",
    }
    default_kwargs.update(kwargs)
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        sns.lineplot(data=data.reshape(-1, data.shape[-1]), x=np.tile(steps, data.shape[0] * data.shape[1]), y=y_axis, hue=tag_sets, **default_kwargs)

    plt.title(title)
    plt.xlabel(x_axis_label)
//  [python]
def plot_avg_return(file_name, granularity):
    plotting_data = torch.load(file_name + "_processed_data")

    returns = plotting_data['returns']
    unique_frames = plotting_data['unique_frames']
    x_len = len(unique_frames)
    x_index = [i for i in numpy.arange(0, x_len, granularity)]

    x = unique_frames[::granularity]
    y = numpy.transpose(numpy.array(returns)[x_index, :])

    f, ax = plt.subplots(1, 1, figsize=[3, 2], dpi=300)
    sns.set_style("ticks")
    sns.set_context("paper")

    # Find the order of magnitude of the last frame
    order = int(math.log10(unique_frames[-1]))
    range_frames = int(unique_frames[-1]/ (10**order))

    sns.tsplot(data=y, time=numpy.array(x)/(10**order), color='b')
    ax.set_xticks(numpy.arange(range_frames + 1))
    plt.show()

    f.savefig(file_name + "_avg_return.pdf", bbox_inches="tight")
    plt.close(f)
//  [python]
def plot_avg_return(file_name, granularity):
    plotting_data = torch.load(file_name + "_processed_data")

    returns = plotting_data['returns']
    unique_frames = plotting_data['unique_frames']
    x_len = len(unique_frames)
    x_index = [i for i in numpy.arange(0, x_len, granularity)]

    x = unique_frames[::granularity]
    y = numpy.transpose(numpy.array(returns)[x_index, :])

    f, ax = plt.subplots(1, 1, figsize=[3, 2], dpi=300)
    sns.set_style("ticks")
    sns.set_context("paper")

    # Find the order of magnitude of the last frame
    order = int(math.log10(unique_frames[-1]))
    range_frames = int(unique_frames[-1]/ (10**order))

    sns.lineplot(data=y, x=numpy.array(x)/(10**order), err_style="band", ci="sd", color='b')
    ax.set_xticks(numpy.arange(range_frames + 1))
    plt.show()

    f.savefig(file_name + "_avg_return.pdf", bbox_inches="tight")
    plt.close(f)
//  [python]
def plot_figs(self, allow_method_names=None):
        plot_table = self.get_pandas_table(allow_method_names)

        ax = sns.tsplot(time=self.x_name, value=self.val_name,
                        unit="unit", condition=self.line_name,
                        data=plot_table, err_style="ci_bars", interpolate=True)
        return ax
//  [python]
def plot_figs(self, allow_method_names=None):
        plot_table = self.get_pandas_table(allow_method_names)

        ax = sns.lineplot(x=self.x_name, y=self.val_name,
                        hue=self.line_name,
                        data=plot_table, err_style="bars")
        return ax
//  [python]
def test():
        dataframe = pd.DataFrame([[1, 2, 0], [2, 3, 0], [3, 4, 1], [4, 5, 1]])
        dataframe.columns = ['col1', 'col2', 'unit']

        ax = sns.tsplot(time='col1', value='col2',
                        unit="unit", ci="sd",
                        data=dataframe, err_style="ci_bars", interpolate=True)
        plt.show()
//  [python]
def test():
        dataframe = pd.DataFrame([[1, 2, 0], [2, 3, 0], [3, 4, 1], [4, 5, 1]])
        dataframe.columns = ['col1', 'col2', 'unit']

        ax = sns.lineplot(x='col1', y='col2',
                        units="unit", err_style="bars",
                        data=dataframe, ci="sd", estimator=None)
        plt.show()
//  [python]
def plot_roc_curve_from_df(
    df, auc_dict_list=None, output_filepath=None, figsize=(6, 6)
):
    """From a df with multiple methods plot a roc curve using sns.tspot."""
    xlabel = 'False Discovery Rate'
    ylabel = 'True Positive Rate'
    title = 'Receiver Operating Characteristic'

    # rename method name to include AUC to show it in legend
    if auc_dict_list:
        for method in auc_dict_list.keys():
            mean_auc = np.mean(auc_dict_list[method])
            method_indices = df['method'] == method
            df['mean_auc'] = mean_auc
            df.loc[method_indices, 'method'] = (
                '{} '.format(
                    method.capitalize()
                    if method != 'INtERAcT'
                    else method
                ) +
                'AUC=%0.2f' % mean_auc
            )
        df = df.sort_values(by='method')

    df.rename(columns={'method': ''}, inplace=True)  # to avoid legend title
    plt.figure(figsize=figsize)
    sns.set_style("whitegrid", {'axes.grid': False})
    sns.tsplot(
        data=df, time='XX', value='YY',
        condition='', unit='pathway', legend=True
    )
    plt.xlim([0, 1])
    plt.ylim([0, 1])
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.title(title)

    if output_filepath:
        plt.savefig(output_filepath, bbox_inches='tight')
//  [python]
def plot_roc_curve_from_df(
    df, auc_dict_list=None, output_filepath=None, figsize=(6, 6)
):
    """From a df with multiple methods plot a roc curve using sns.tspot."""
    xlabel = 'False Discovery Rate'
    ylabel = 'True Positive Rate'
    title = 'Receiver Operating Characteristic'

    # rename method name to include AUC to show it in legend
    if auc_dict_list:
        for method in auc_dict_list.keys():
            mean_auc = np.mean(auc_dict_list[method])
            method_indices = df['method'] == method
            df['mean_auc'] = mean_auc
            df.loc[method_indices, 'method'] = (
                '{} '.format(
                    method.capitalize()
                    if method != 'INtERAcT'
                    else method
                ) +
                'AUC=%0.2f' % mean_auc
            )
        df = df.sort_values(by='method')

    df.rename(columns={'method': ''}, inplace=True)  # to avoid legend title
    plt.figure(figsize=figsize)
    sns.set_style("whitegrid", {'axes.grid': False})
    sns.lineplot(
        data=df, x='XX', y='YY',
        hue='', units='pathway', legend=True
    )
    plt.xlim([0, 1])
    plt.ylim([0, 1])
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.title(title)

    if output_filepath:
        plt.savefig(output_filepath, bbox_inches='tight')
//  [python]
def tsplot():
    gammas = sns.load_dataset('gammas')
    sns.tsplot(data=gammas, time='timepoint', unit='subject', 
               condition='ROI', value='BOLD signal', 
               err_style="ci_band", ci=68, interpolate=True, 
               color=None, estimator=np.mean, n_boot=5000, 
               err_palette=None, err_kws=None, legend=True, 
               ax=None)
    sns.plt.show()
//  [python]
def tsplot():
    gammas = sns.load_dataset('gammas')
    sns.lineplot(data=gammas, x='timepoint', y='BOLD signal', hue='ROI', 
               ci=68, estimator=np.mean, n_boot=5000)
    sns.plt.show()
//  [python]
def visualize(self, tsv_name, lower_axis=0, higher_axis=1):
        """
        Given a CSV file that has clusters, visualize each of those clusters based on the original normalized values.

        :param tsv_name:    The name of the TSV file to visualize the clusters of
        :param lower_axis:  The lower bound of each graph, default 0
        :param higher_axis: The upper bound of each graph, default 1
        :return:
        """
        visualization_path = os.path.join(self.output_directory, "Visualizations")
        if not os.path.exists(visualization_path):
            os.makedirs(visualization_path)
        if self.verbose:
            print("Loading large CSV into dataframe")
        df = pd.DataFrame.from_csv(os.path.join(self.output_directory, tsv_name + ".tsv"),
                                   index_col=None,
                                   sep=magic.separator)

        if self.verbose:
            print("Finished loading CSV into dataframe")

        for ci in range(0, self.number_of_clusters):
            cluster = df[df["cluster"] == ci]
            if self.verbose:
                print("Cluster {}".format(ci))
            just_time_values = \
                cluster.drop(["mz", "mzmin", "mzmax", "rt", "rtmin",
                              "rtmax", "into", "maxo", "exp_maxo", "ctrl_maxo",
                              "cluster", "sn", "abs_sn", "exp_std_dev", "ctrl_std_dev"], 1)

            if self.verbose:
                print("Creating plot")
            if len(just_time_values) == 0:
                continue

            sns.tsplot(just_time_values.as_matrix(), color="indianred", err_style="unit_traces")

            # Count first so we can order by count easily.
            save_location = os.path.join(visualization_path, "{}_Cluster_{}.png".format(ci, len(just_time_values)))
            if self.verbose:
                print("Saving plot at {}".format(save_location))

            sns.plt.ylim(lower_axis, higher_axis)
            sns.plt.title("Cluster {} : Count {}".format(ci, len(cluster)))
            sns.plt.savefig(save_location)

            # Make sure to clear after creating each figure.
            sns.plt.cla()
            sns.plt.clf()
//  [python]
def visualize(self, tsv_name, lower_axis=0, higher_axis=1):
        """
        Given a CSV file that has clusters, visualize each of those clusters based on the original normalized values.

        :param tsv_name:    The name of the TSV file to visualize the clusters of
        :param lower_axis:  The lower bound of each graph, default 0
        :param higher_axis: The upper bound of each graph, default 1
        :return:
        """
        visualization_path = os.path.join(self.output_directory, "Visualizations")
        if not os.path.exists(visualization_path):
            os.makedirs(visualization_path)
        if self.verbose:
            print("Loading large CSV into dataframe")
        df = pd.DataFrame.from_csv(os.path.join(self.output_directory, tsv_name + ".tsv"),
                                   index_col=None,
                                   sep=magic.separator)

        if self.verbose:
            print("Finished loading CSV into dataframe")

        for ci in range(0, self.number_of_clusters):
            cluster = df[df["cluster"] == ci]
            if self.verbose:
                print("Cluster {}".format(ci))
            just_time_values = \
                cluster.drop(["mz", "mzmin", "mzmax", "rt", "rtmin",
                              "rtmax", "into", "maxo", "exp_maxo", "ctrl_maxo",
                              "cluster", "sn", "abs_sn", "exp_std_dev", "ctrl_std_dev"], 1)

            if self.verbose:
                print("Creating plot")
            if len(just_time_values) == 0:
                continue

            sns.lineplot(data=just_time_values.T, color="indianred")

            # Count first so we can order by count easily.
            save_location = os.path.join(visualization_path, "{}_Cluster_{}.png".format(ci, len(just_time_values)))
            if self.verbose:
                print("Saving plot at {}".format(save_location))

            sns.plt.ylim(lower_axis, higher_axis)
            sns.plt.title("Cluster {} : Count {}".format(ci, len(cluster)))
            sns.plt.savefig(save_location)

            # Make sure to clear after creating each figure.
            sns.plt.cla()
            sns.plt.clf()
//  [python]
def plot_hyp(hyp_keys, exp_param, meth, data,
             s_sch="u_rand"):
    for exp in exp_param:
        df = pd.read_hdf(
            "intermediate/%s_%s_%s_%s_hyp.h5" % (data, meth, exp, s_sch),
            "df"
        )
        col_names = df.columns
        col_rename_d = {}
        for col_name in col_names:
            col_rename_d[col_name] = col_name.replace('_', '\ ')
        df.rename(columns=col_rename_d, inplace=True)
        for hyp_key in hyp_keys:
            hyp_key_ren = hyp_key.replace('_', '\ ')
            df_trun = df[[hyp_key_ren, "Round Id", expMap[exp]]]
            try:
                df_grouped = df_trun.groupby([hyp_key_ren, "Round Id"]).max().reset_index()
            except TypeError:
                df_trun[hyp_key_ren + "2"] = \
                    df_trun[hyp_key_ren].apply(lambda x: str(x))
                df_trun[hyp_key_ren] = df_trun[hyp_key_ren + "2"].copy()
                df_trun = df_trun.drop([hyp_key_ren + "2"], axis=1)
                df_grouped = df_trun.groupby([hyp_key_ren, "Round Id"]).max().reset_index()
            if len(df_grouped[hyp_key_ren].unique()) < 3:
                continue
            try:
                print('Plotting %s: %s' % (exp, hyp_key))
                ax = seaborn.tsplot(time=hyp_key_ren, value=expMap[exp],
                                    unit="Round Id", data=df_grouped)
                hyp_values = df_grouped[hyp_key_ren].unique()
                l_diff = hyp_values[-1] - hyp_values[-2]
                f_diff = hyp_values[1] - hyp_values[0]
                l_f_diff_r = l_diff / f_diff
                if l_f_diff_r > 1:
                    log_base = pow(l_f_diff_r, 1.0 / (len(hyp_values) - 2))
                    ax.set_xscale('log', basex=round(log_base))
                marker = ["o", "s", "D", "^", "v", "8", "*", "p", "1", "h"]
                for line_i in range(len(ax.lines)):
                    ax.lines[line_i].set_marker(marker[line_i])
                # ax.grid()
                ax.legend()
            except ValueError:
                ax = seaborn.barplot(x=hyp_key_ren, y=expMap[exp], data=df_grouped)
            except ZeroDivisionError:
                print( 'Only 2 points provided to plot hyperparameters')
                continue
            plt.savefig(
                'plots/hyp/%s_%s_%s_%s_%s.pdf' % (data, meth, exp, s_sch, hyp_key),
                dpi=300, format='pdf', bbox_inches='tight'
            )
            plt.clf()
//  [python]
def plot_hyp(hyp_keys, exp_param, meth, data,
             s_sch="u_rand"):
    for exp in exp_param:
        df = pd.read_hdf(
            "intermediate/%s_%s_%s_%s_hyp.h5" % (data, meth, exp, s_sch),
            "df"
        )
        col_names = df.columns
        col_rename_d = {}
        for col_name in col_names:
            col_rename_d[col_name] = col_name.replace('_', '\ ')
        df.rename(columns=col_rename_d, inplace=True)
        for hyp_key in hyp_keys:
            hyp_key_ren = hyp_key.replace('_', '\ ')
            df_trun = df[[hyp_key_ren, "Round Id", expMap[exp]]]
            try:
                df_grouped = df_trun.groupby([hyp_key_ren, "Round Id"]).max().reset_index()
            except TypeError:
                df_trun[hyp_key_ren + "2"] = \
                    df_trun[hyp_key_ren].apply(lambda x: str(x))
                df_trun[hyp_key_ren] = df_trun[hyp_key_ren + "2"].copy()
                df_trun = df_trun.drop([hyp_key_ren + "2"], axis=1)
                df_grouped = df_trun.groupby([hyp_key_ren, "Round Id"]).max().reset_index()
            if len(df_grouped[hyp_key_ren].unique()) < 3:
                continue
            try:
                print('Plotting %s: %s' % (exp, hyp_key))
                ax = seaborn.lineplot(x=hyp_key_ren, y=expMap[exp],
                                    hue="Round Id", data=df_grouped)
                hyp_values = df_grouped[hyp_key_ren].unique()
                l_diff = hyp_values[-1] - hyp_values[-2]
                f_diff = hyp_values[1] - hyp_values[0]
                l_f_diff_r = l_diff / f_diff
                if l_f_diff_r > 1:
                    log_base = pow(l_f_diff_r, 1.0 / (len(hyp_values) - 2))
                    ax.set_xscale('log', basex=round(log_base))
                marker = ["o", "s", "D", "^", "v", "8", "*", "p", "1", "h"]
                for line_i in range(len(ax.lines)):
                    ax.lines[line_i].set_marker(marker[line_i])
                # ax.grid()
                ax.legend()
            except ValueError:
                ax = seaborn.barplot(x=hyp_key_ren, y=expMap[exp], data=df_grouped)
            except ZeroDivisionError:
                print( 'Only 2 points provided to plot hyperparameters')
                continue
            plt.savefig(
                'plots/hyp/%s_%s_%s_%s_%s.pdf' % (data, meth, exp, s_sch, hyp_key),
                dpi=300, format='pdf', bbox_inches='tight'
            )
            plt.clf()
//  [python]
def plot_data(data, xaxis='Epoch', value="AverageEpRet", condition="Condition1", smooth=1, no_legend=False, legend_loc='best', color=None, font_scale=1.5, **kwargs):
    if smooth > 1:
        """
        smooth data with moving window average.
        that is,
            smoothed_y[t] = average(y[t-k], y[t-k+1], ..., y[t+k-1], y[t+k])
        where the "smooth" param is width of that window (2k+1)
        """
        y = np.ones(smooth)
        for datum in data:
            x = np.asarray(datum[value])
            z = np.ones(len(x))
            smoothed_x = np.convolve(x,y,'same') / np.convolve(z,y,'same')
            datum[value] = smoothed_x

    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=font_scale)
    # sns.set_palette('bright')

    print("##############")

    ## TODO CHANGE BACK
    sns.tsplot(data=data, time=xaxis, value=value, unit="Unit", condition=condition, legend=(not no_legend), ci='sd', n_boot=0, color=color, **kwargs)
    plt.xlabel('environment interactions')
    plt.ylabel('average test return')

    """
    If you upgrade to any version of Seaborn greater than 0.8.1, switch from 
    tsplot to lineplot replacing L29 with:

        sns.lineplot(data=data, x=xaxis, y=value, hue=condition, ci='sd', **kwargs)

    Changes the colorscheme and the default legend style, though.
    """
    if not no_legend:
        plt.legend(loc=legend_loc).draggable()

    """
    For the version of the legend used in the Spinning Up benchmarking page, 
    swap L38 with:

    plt.legend(loc='upper center', ncol=6, handlelength=1,
               mode="expand", borderaxespad=0., prop={'size': 13})
    """

    xscale = np.max(np.asarray(data[xaxis])) > 5e3
    if xscale:
        # Just some formatting niceness: x-axis scale in scientific notation if max x is large
        plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))

    plt.tight_layout(pad=0.5)
//  [python]
def plot_data(data, xaxis='Epoch', value="AverageEpRet", condition="Condition1", smooth=1, no_legend=False, legend_loc='best', color=None, font_scale=1.5, **kwargs):
    if smooth > 1:
        """
        smooth data with moving window average.
        that is,
            smoothed_y[t] = average(y[t-k], y[t-k+1], ..., y[t+k-1], y[t+k])
        where the "smooth" param is width of that window (2k+1)
        """
        y = np.ones(smooth)
        for datum in data:
            x = np.asarray(datum[value])
            z = np.ones(len(x))
            smoothed_x = np.convolve(x,y,'same') / np.convolve(z,y,'same')
            datum[value] = smoothed_x

    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    sns.set(style="darkgrid", font_scale=font_scale)
    # sns.set_palette('bright')

    print("##############")

    sns.lineplot(data=data, x=xaxis, y=value, hue=condition, ci='sd', **kwargs)
    plt.xlabel('environment interactions')
    plt.ylabel('average test return')

    if not no_legend:
        plt.legend(loc=legend_loc).draggable()

    xscale = np.max(np.asarray(data[xaxis])) > 5e3
    if xscale:
        # Just some formatting niceness: x-axis scale in scientific notation if max x is large
        plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))

    plt.tight_layout(pad=0.5)
//  [python]
def subplot_data(data, ax, value="mean", title=None, min_score=None, max_score=None):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    if min_score is not None and max_score is not None:
        scale = float(max_score) - float(min_score)
        data[value] = (data[value] - float(min_score)) / scale
    sns.tsplot(data=data, time="Iteration", value=value, unit="Unit", condition="Condition", ax=ax)
    ax.set_xlabel(None)
    ax.set_ylabel(None)
    if title is not None:
        plt.title(title)
    if min_score is not None and max_score is not None:
        ax.set_yticks(np.arange(0.0, 1.1, 0.1))
    ax.xaxis.set_major_locator(MaxNLocator(integer=True))
    ax.get_legend().remove()
    return ax
//  [python]
def subplot_data(data, ax, value="mean", title=None, min_score=None, max_score=None):
    if isinstance(data, list):
        data = pd.concat(data, ignore_index=True)
    if min_score is not None and max_score is not None:
        scale = float(max_score) - float(min_score)
        data[value] = (data[value] - float(min_score)) / scale
    sns.lineplot(data=data, x="Iteration", y=value, hue="Condition", units="Unit", ax=ax)
    ax.set_xlabel(None)
    ax.set_ylabel(None)
    if title is not None:
        plt.title(title)
    if min_score is not None and max_score is not None:
        ax.set_yticks(np.arange(0.0, 1.1, 0.1))
    ax.xaxis.set_major_locator(MaxNLocator(integer=True))
    ax.get_legend().remove()
    return ax
//  [python]
def plot_data(data, xaxis="Epoch", value="AverageEpRet", condition="Condition1", smooth=1, env_name=None, **kwargs):
	if smooth > 1:
		"""
		smooth data with moving window average.
		that is,
			smoothed_y[t] = average(y[t-k], y[t-k+1], ..., y[t+k-1], y[t+k])
		where the "smooth" param is width of that window (2k+1)
		"""
		y = np.ones(smooth)
		for datum in data:
			x = np.asarray(datum[value])
			z = np.ones(len(x))
			smoothed_x = np.convolve(x, y, "same") / np.convolve(z, y, "same")
			datum[value] = smoothed_x

	if isinstance(data, list):
		data = pd.concat(data, ignore_index=True)

	# for NeurIPS seven plots.
	flatui = ["#4B72B0", "#55A868", "#C44E51", "#8172B1", "#E377C1", "#64B4CD", "#FF7400"]
	# for NeurIPS six plots.
	# flatui = ["#55A868", "#C44E51", "#8172B1", "#E377C1", "#64B4CD", "#FF7400"]
	sns.set(style="white", palette=sns.color_palette(flatui), color_codes=False, font_scale=1.5)
	# Default
	# sns.set(style="white", font_scale=1.5)
	ax = sns.tsplot(data=data, time=xaxis, value=value, unit="Unit", condition=condition, ci="sd", **kwargs)
	# ax = sns.lineplot(data=data, x=xaxis, y=value, hue=condition, ci="sd", **kwargs)
	
	ax.set_xlabel("Steps")
	ax.set_xlim([0.0, 3000000.0])

	if env_name is not None:
		ax.set_title(label=env_name)
	"""
	If you upgrade to any version of Seaborn greater than 0.8.1, switch from 
	tsplot to lineplot replacing L34 with:

		sns.lineplot(data=data, x=xaxis, y=value, hue=condition, ci="sd", **kwargs)

	Changes the colorscheme and the default legend style, though.
	"""
	plt.legend(loc="best").set_draggable(True)
	plt.tick_params(direction="out", length=4)
	"""
	For the version of the legend used in the Spinning Up benchmarking page, 
	swap L38 with:

	plt.legend(loc="upper center", ncol=6, handlelength=1,
			   mode="expand", borderaxespad=0., prop={"size": 13})
	"""

	xscale = np.max(np.asarray(data[xaxis])) > 5e3
	if xscale:
		# Just some formatting niceness: x-axis scale in scientific notation if max x is large
		plt.ticklabel_format(style="sci", axis='x', scilimits=(0, 0))

	plt.tight_layout(pad=0.5)