jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def compare_mask(df_all, df_iid, df_ood, args):
    values = df_all.amin.unique()

    stack_iid = list()
    stack_ood = list()
    for val in values:
        df_all_setting, df_iid_setting, df_ood_setting = extract_setting(df_all, df_iid, df_ood,
            args.bbox, args.ood, args.model, args.critic_action, args.critic_state, 
            args.finetune, args.translation, args.mask, val)
        stack_iid.append(df_iid_setting[['epoch', 'iid', 'amin', 'seed']])
        stack_ood.append(df_ood_setting[['epoch', 'ood', 'amin', 'seed']])
    df_iid_setting = pd.concat(stack_iid)
    df_ood_setting = pd.concat(stack_ood)

    # stats
    pd.options.display.float_format = '{:,.3f}'.format
    print(df_iid_setting.groupby('amin').mean(), df_iid_setting.groupby('amin').std())
    print(df_ood_setting.groupby('amin').mean(), df_ood_setting.groupby('amin').std())

    plt.figure(figsize=(4,3))

    # mask impact
    ax = sns.pointplot(x=df_iid_setting.groupby('amin').mean().index, y=df_iid_setting.groupby('amin').mean().iid)
    ax.set_xlim([0.004, 1.0])
    ax.set_xlabel('min mask value')
    ax.set_ylabel('accuracy')
    ax.set_xscale('log') 
    plt.savefig(args.foldername+'/summary_iid_mask.png', bbox_inches='tight')

    plt.clf()

    ax = sns.pointplot(x=df_ood_setting.groupby('amin').mean().index, y=df_ood_setting.groupby('amin').mean().ood)
    ax.set_xlim([0.004, 1.0])
    ax.set_xlabel('min mask value')
    ax.set_ylabel('accuracy')
    ax.set_xscale('log') 
    plt.savefig(args.foldername+'/summary_ood_mask.png', bbox_inches='tight')

    plt.clf()

    df_ood_group = df_ood_setting.groupby('amin').mean()
    best_amin = df_ood_group.index[df_ood_group.ood.argmax()]

    print('optimal mask:', best_amin)

    # fig
    df_comp = pd.DataFrame({'vanilla': df_iid_setting[df_iid_setting['amin']==1.0].iid.to_numpy(), 
                            'mask': df_iid_setting[df_iid_setting['amin']==best_amin].iid.to_numpy()})
    print(df_comp)
    vmin = 0.8
    vmax = 0.925
    vbin = 0.025
    vtick = np.linspace(vmin, vmax, round((vmax-vmin)/vbin)+1)
    ax = sns.scatterplot(data=df_comp, x='vanilla', y='mask')
    ax.set_aspect('equal')
    ax.set_xlim([vmin, vmax])
    ax.set_ylim([vmin, vmax])
    ax.plot([vmin, vmax], [vmin, vmax], '-r')
    ax.set_xticks(vtick)
    ax.set_yticks(vtick)
    plt.savefig(args.foldername+'/compare_iid_mask.png', bbox_inches='tight')

    plt.clf()

    df_comp = pd.DataFrame({'vanilla': df_ood_setting[df_ood_setting['amin']==1.0].ood.to_numpy(), 
                            'mask': df_ood_setting[df_ood_setting['amin']==best_amin].ood.to_numpy()})
    print(df_comp)
    vmin = 0.1
    vmax = 0.6
    vbin = 0.1
    vtick = np.linspace(vmin, vmax, round((vmax-vmin)/vbin)+1)
    ax = sns.scatterplot(data=df_comp, x='vanilla', y='mask')
    ax.set_aspect('equal')
    ax.set_xlim([vmin, vmax])
    ax.set_ylim([vmin, vmax])
    ax.plot([vmin, vmax], [vmin, vmax], '-r')
    ax.set_xticks(vtick)
    ax.set_yticks(vtick)
    plt.savefig(args.foldername+'/compare_ood_mask.png', bbox_inches='tight')
//  [python]
def compare_mask(df_all, df_iid, df_ood, args):
    values = df_all.amin.unique()

    stack_iid = list()
    stack_ood = list()
    for val in values:
        df_all_setting, df_iid_setting, df_ood_setting = extract_setting(df_all, df_iid, df_ood,
            args.bbox, args.ood, args.model, args.critic_action, args.critic_state, 
            args.finetune, args.translation, args.mask, val)
        stack_iid.append(df_iid_setting[['epoch', 'iid', 'amin', 'seed']])
        stack_ood.append(df_ood_setting[['epoch', 'ood', 'amin', 'seed']])
    df_iid_setting = pd.concat(stack_iid)
    df_ood_setting = pd.concat(stack_ood)

    # stats
    pd.options.display.float_format = '{:,.3f}'.format
    print(df_iid_setting.groupby('amin').mean(), df_iid_setting.groupby('amin').std())
    print(df_ood_setting.groupby('amin').mean(), df_ood_setting.groupby('amin').std())

    plt.figure(figsize=(4,3))

    # mask impact
    ax = sns.lineplot(x=df_iid_setting.groupby('amin').mean().index, y=df_iid_setting.groupby('amin').mean().iid, markers=True)
    ax.set_xlim([0.004, 1.0])
    ax.set_xlabel('min mask value')
    ax.set_ylabel('accuracy')
    ax.set_xscale('log') 
    plt.savefig(args.foldername+'/summary_iid_mask.png', bbox_inches='tight')

    plt.clf()

    ax = sns.lineplot(x=df_ood_setting.groupby('amin').mean().index, y=df_ood_setting.groupby('amin').mean().ood, markers=True)
    ax.set_xlim([0.004, 1.0])
    ax.set_xlabel('min mask value')
    ax.set_ylabel('accuracy')
    ax.set_xscale('log') 
    plt.savefig(args.foldername+'/summary_ood_mask.png', bbox_inches='tight')

    plt.clf()

    df_ood_group = df_ood_setting.groupby('amin').mean()
    best_amin = df_ood_group.index[df_ood_group.ood.argmax()]

    print('optimal mask:', best_amin)

    # fig
    df_comp = pd.DataFrame({'vanilla': df_iid_setting[df_iid_setting['amin']==1.0].iid.to_numpy(), 
                            'mask': df_iid_setting[df_iid_setting['amin']==best_amin].iid.to_numpy()})
    print(df_comp)
    vmin = 0.8
    vmax = 0.925
    vbin = 0.025
    vtick = np.linspace(vmin, vmax, round((vmax-vmin)/vbin)+1)
    ax = sns.scatterplot(data=df_comp, x='vanilla', y='mask')
    ax.set_aspect('equal')
    ax.set_xlim([vmin, vmax])
    ax.set_ylim([vmin, vmax])
    ax.plot([vmin, vmax], [vmin, vmax], '-r')
    ax.set_xticks(vtick)
    ax.set_yticks(vtick)
    plt.savefig(args.foldername+'/compare_iid_mask.png', bbox_inches='tight')

    plt.clf()

    df_comp = pd.DataFrame({'vanilla': df_ood_setting[df_ood_setting['amin']==1.0].ood.to_numpy(), 
                            'mask': df_ood_setting[df_ood_setting['amin']==best_amin].ood.to_numpy()})
    print(df_comp)
    vmin = 0.1
    vmax = 0.6
    vbin = 0.1
    vtick = np.linspace(vmin, vmax, round((vmax-vmin)/vbin)+1)
    ax = sns.scatterplot(data=df_comp, x='vanilla', y='mask')
    ax.set_aspect('equal')
    ax.set_xlim([vmin, vmax])
    ax.set_ylim([vmin, vmax])
    ax.plot([vmin, vmax], [vmin, vmax], '-r')
    ax.set_xticks(vtick)
    ax.set_yticks(vtick)
    plt.savefig(args.foldername+'/compare_ood_mask.png', bbox_inches='tight')
//  [python]
def clineplot(fname: str,
              xCol: str,
              yCol: str,
              figTitle: str = None,
              figWidth: int = 16,
              figHeight: int = 6,
              plotDir: str = "plots") -> None:
    
    sns.set(color_codes=True)
    if not os.path.isdir(plotDir):
        os.mkdir(plotDir)
    df = pd.read_csv(fname)
    fig = plt.figure(figsize=(figWidth, figHeight))
    ax = sns.tsplot(x=xCol, y=yCol, data=df)
    plt.title(f"{figTitle}")
    plt.savefig(f"./{plotDir}/{figTitle}.png")
    plt.close()
//  [python]
def clineplot(fname: str,
              xCol: str,
              yCol: str,
              figTitle: str = None,
              figWidth: int = 16,
              figHeight: int = 6,
              plotDir: str = "plots") -> None:
    
    sns.set(color_codes=True)
    if not os.path.isdir(plotDir):
        os.mkdir(plotDir)
    df = pd.read_csv(fname)
    fig = plt.figure(figsize=(figWidth, figHeight))
    ax = sns.lineplot(x=xCol, y=yCol, data=df)
    plt.title(f"{figTitle}")
    plt.savefig(f"./{plotDir}/{figTitle}.png")
    plt.close()
//  [python]
def postprocess(self, workdir: Path, database: Database):
        import seaborn as sns

        df = (
            DataFrameExtractor(database)
            .extract("index", "duration", "environment")
            .transform("task-count", lambda r: r.workload_params["task_count"])
            .build()
        )

        ax = sns.lineplot(x="task-count", y="duration", hue="environment", data=df, marker="o")
        ax.set(ylabel="Duration [s]", xlabel="Task count", ylim=(0, None))
        # ax.set(yscale="log")
        render_chart_to_png(workdir / "dask-vs-hq-empty.png")
//  [python]
def postprocess(self, workdir: Path, database: Database):
        import seaborn as sns

        df = (
            DataFrameExtractor(database)
            .extract("index", "duration", "environment")
            .transform("task-count", lambda r: r.workload_params["task_count"])
            .build()
        )

        ax = sns.lineplot(df, x="task-count", y="duration", hue="environment", marker="o")
        ax.set(ylabel="Duration [s]", xlabel="Task count", ylim=(0, None))
        # ax.set(yscale="log")
        render_chart_to_png(workdir / "dask-vs-hq-empty.png")
//  [python]
def plot_signal(sr, signal, labels, signal_id):
    """Utilitary function to plot an audio signal.

    Args:
        sr (int): audio signal sampling rate
        signal (np.ndarray): audio signal
        labels (dict): dictionary of labels (0 or 1)
        signal_id (str): signal id
    """
    logger.info(
        f"Sampling rate = {sr} | Num. points = {len(signal)} | Tot. duration = {len(signal) / sr:.2f} s"
    )
    plt.figure(figsize=(15, 10))
    sns.set()
    plt.plot([i / sr for i in range(len(signal))], signal)

    start, end = 0, 0
    for seg in labels["speech_segments"]:
        plt.axvspan(end, seg["start_time"] / sr, alpha=0.5, color="r")
        start, end = seg["start_time"] / sr, seg["end_time"] / sr
        plt.axvspan(start, end, alpha=0.5, color="g")
    plt.axvspan(end, (len(signal) - 1) / sr, alpha=0.5, color="r")

    plt.title(f"Sample number {signal_id} with speech in green", size=20)
    plt.xlabel("Time (s)", size=20)
    plt.ylabel("Amplitude", size=20)
    plt.xticks(size=15)
    plt.yticks(size=15)
    plt.show()
//  [python]
def plot_signal(sr, signal, labels, signal_id):
    """Utilitary function to plot an audio signal.

    Args:
        sr (int): audio signal sampling rate
        signal (np.ndarray): audio signal
        labels (dict): dictionary of labels (0 or 1)
        signal_id (str): signal id
    """
    logger.info(
        f"Sampling rate = {sr} | Num. points = {len(signal)} | Tot. duration = {len(signal) / sr:.2f} s"
    )
    plt.figure(figsize=(15, 10))
    sns.set()
    sns.lineplot(x=[i / sr for i in range(len(signal))], y=signal)

    start, end = 0, 0
    for seg in labels["speech_segments"]:
        plt.axvspan(end, seg["start_time"] / sr, alpha=0.5, color="r")
        start, end = seg["start_time"] / sr, seg["end_time"] / sr
        plt.axvspan(start, end, alpha=0.5, color="g")
    plt.axvspan(end, (len(signal) - 1) / sr, alpha=0.5, color="r")

    plt.title(f"Sample number {signal_id} with speech in green", size=20)
    plt.xlabel("Time (s)", size=20)
    plt.ylabel("Amplitude", size=20)
    plt.xticks(size=15)
    plt.yticks(size=15)
    plt.show()
//  [python]
def nice_plot_history(self, history, added_plots = [], no_val=False, show=True, save=False, name="lastplot", max_y = 1.0):
        fig, ax = plt.subplots()

        loss = history.history["loss"]
        accuracy = history.history["acc"]
        if not no_val:
            val_loss = history.history["val_loss"]
            val_accuracy = history.history["val_acc"]

        data = [loss, accuracy]
        columns = ['loss', 'accuracy']

        if not no_val:
            data = [loss, val_loss, accuracy, val_accuracy]
            columns = ['loss', 'val_loss', 'acc', 'val_acc']


        if len(added_plots)>0:
            for item in added_plots:
                data += [history.history[item]]
                columns += [item]

        if self.settings.verbose > 2:
            print(data)
            print(columns)

        df = pd.DataFrame(data)
        df = df.transpose()
        df.columns = columns

        if self.settings.verbose > 2:
            print(df)

        accuracies = []
        losses = []

        def plot_item(name, color, max_wanted=True):
            line_item = plt.plot(df.index, df[name], label=name, color=color)
            if max_wanted:
                max_y = df[name].max()
                max_idx = df[name].idxmax()
            else:
                max_y = df[name].min()
                max_idx = df[name].idxmin()

            text_item = plt.text(max_idx + 0.2, max_y + 0.05, str(round(max_y, 2)), horizontalalignment='left',
                                 size='medium', color=color, weight='semibold')
            return [line_item, text_item]

        accuracies += plot_item("acc", "blue")
        if not no_val:
            accuracies += plot_item("val_acc", "orange")

        losses += plot_item("loss", "green", max_wanted=False)
        max_val = df["acc"].max()

        if not no_val:
            losses += plot_item("val_loss", "brown", max_wanted=False)
            max_val = max(df["loss"].max(), df["val_loss"].max())

        if len(added_plots)>0:
            for item in added_plots:
                plot_item(item, "grey")

        plt.ylim(0, max_y)
        plt.ylabel("Accuracy")

        plt.legend(loc='lower right')  # best

        def press(event):
            sys.stdout.flush()
            if event.key == '+':
                # zoom to 0-1 accuracy
                plt.ylim(0, 1)
            elif event.key == '-':
                plt.ylim(0, max_val)
            elif event.key == 'b':
                plt.legend(loc='best')
            elif event.key == 'a':
                plt.legend(loc='lower right')
            else:
                print('press', event.key)

            fig.canvas.draw()

        fig.canvas.mpl_connect('key_press_event', press)

        if show:
            plt.show()
        if save:
            plt.savefig(name+".png")
            #plt.savefig(name+".pdf")

        plt.close()
//  [python]
def nice_plot_history(self, history, added_plots = [], no_val=False, show=True, save=False, name="lastplot", max_y = 1.0):
        fig, ax = plt.subplots()

        loss = history.history["loss"]
        accuracy = history.history["acc"]
        if not no_val:
            val_loss = history.history["val_loss"]
            val_accuracy = history.history["val_acc"]

        data = [loss, accuracy]
        columns = ['loss', 'accuracy']

        if not no_val:
            data = [loss, val_loss, accuracy, val_accuracy]
            columns = ['loss', 'val_loss', 'acc', 'val_acc']


        if len(added_plots)>0:
            for item in added_plots:
                data += [history.history[item]]
                columns += [item]

        if self.settings.verbose > 2:
            print(data)
            print(columns)

        df = pd.DataFrame(data)
        df = df.transpose()
        df.columns = columns

        if self.settings.verbose > 2:
            print(df)

        accuracies = []
        losses = []

        def plot_item(name, color, max_wanted=True):
            line_item = sns.lineplot(y=name, x=df.index, data=df, label=name)
            if max_wanted:
                max_y = df[name].max()
                max_idx = df[name].idxmax()
            else:
                max_y = df[name].min()
                max_idx = df[name].idxmin()

            text_item = plt.text(max_idx + 0.2, max_y + 0.05, str(round(max_y, 2)), horizontalalignment='left',
                                 size='medium', color=color, weight='semibold')
            return [line_item, text_item]

        accuracies += plot_item("acc", "blue")
        if not no_val:
            accuracies += plot_item("val_acc", "orange")

        losses += plot_item("loss", "green", max_wanted=False)
        max_val = df["acc"].max()

        if not no_val:
            losses += plot_item("val_loss", "brown", max_wanted=False)
            max_val = max(df["loss"].max(), df["val_loss"].max())

        if len(added_plots)>0:
            for item in added_plots:
                plot_item(item, "grey")

        plt.ylim(0, max_y)
        plt.ylabel("Accuracy")

        plt.legend(loc='lower right')  # best

        def press(event):
            sys.stdout.flush()
            if event.key == '+':
                # zoom to 0-1 accuracy
                plt.ylim(0, 1)
            elif event.key == '-':
                plt.ylim(0, max_val)
            elif event.key == 'b':
                plt.legend(loc='best')
            elif event.key == 'a':
                plt.legend(loc='lower right')
            else:
                print('press', event.key)

            fig.canvas.draw()

        fig.canvas.mpl_connect('key_press_event', press)

        if show:
            plt.show()
        if save:
            plt.savefig(name+".png")
            #plt.savefig(name+".pdf")

        plt.close()
//  [python]
plt.title('Image Title')
# Plot will be reported automatically
plt.show()

sns.set(style="darkgrid")
# Load an example dataset with long-form data
fmri = sns.load_dataset("fmri")
# Plot the responses for different events and regions
sns.pointplot(x="timepoint", y="signal",
             hue="region", style="event",
             data=fmri)
//  [python]
plt.title('Image Title')
# Plot will be reported automatically
plt.show()

sns.set(style="darkgrid")
# Load an example dataset with long-form data
fmri = sns.load_dataset("fmri")
# Plot the responses for different events and regions
sns.lineplot(x="timepoint", y="signal",
             hue="region", style="event",
             data=fmri)
//  [python]
def plot_endpoint(self, endpoint, x='index', label=None, chemistry_filters_basic=False, chemistry_filter_target=False,
                      window=100):
        """
        Return the axis of a plot
        :param x: Either "index" or "step"
        :param y: Endpoint to plot
        :param label: Label for the legend
        :param chemistry_filters_basic:
        :param chemistry_filters_target:
        :param window: If plotting index, what window to average values over
        """
        if label is None:
            label = endpoint

        tdf = self.filter(basic=chemistry_filters_basic, target=chemistry_filter_target)
        
        if endpoint not in tdf.columns:
            print(f"Couldn't find endpoint {endpoint} for plotting")
            return
        
        if x == 'index':
            tdf['window'] = (np.arange(len(tdf))//window) + 1
            ax = sns.tsplot(data=tdf, time='window', value=endpoint, unit="unit", condition=label.capitalize(), err_style="band", palette='husl')
            xlabels = [f'{int(x)*window/1000:.1f}k' for x in ax.get_xticks()]
            ax.set_xticklabels(xlabels)
        
        else:
            ax = sns.tsplot(data=tdf, time=x, value=endpoint, unit="unit", condition=label.capitalize(), err_style="band", palette='husl')
        
        ax.set_xlabel(x.capitalize())
        ax.set_ylabel("Value")
        ax.set_xlim(0, None)
        return ax
//  [python]
def plot_endpoint(self, endpoint, x='index', label=None, chemistry_filters_basic=False, chemistry_filter_target=False,
                      window=100):
        """
        Return the axis of a plot
        :param x: Either "index" or "step"
        :param y: Endpoint to plot
        :param label: Label for the legend
        :param chemistry_filters_basic:
        :param chemistry_filters_target:
        :param window: If plotting index, what window to average values over
        """
        if label is None:
            label = endpoint

        tdf = self.filter(basic=chemistry_filters_basic, target=chemistry_filter_target)
        
        if endpoint not in tdf.columns:
            print(f"Couldn't find endpoint {endpoint} for plotting")
            return
        
        if x == 'index':
            tdf['window'] = (np.arange(len(tdf))//window) + 1
            ax = sns.lineplot(data=tdf, x='window', y=endpoint, label=label.capitalize(), palette='husl')
            xlabels = [f'{int(x)*window/1000:.1f}k' for x in ax.get_xticks()]
            ax.set_xticklabels(xlabels)
        
        else:
            ax = sns.lineplot(data=tdf, x=x, y=endpoint, label=label.capitalize(), palette='husl')
        
        ax.set_xlabel(x.capitalize())
        ax.set_ylabel("Value")
        ax.set_xlim(0, None)
        return ax
//  [python]
def plot_yield(self,
        endpoint, threshold, label=None, window=100, extrapolate=True, scaffold=False,
        chemistry_filters_basic=False, chemistry_filter_target=False
    ):
        """
        Plot the yield according to some endpoint and threshold, example, ratio of molecules with reward > 0.8.
        """
        if label is None:
            label = endpoint

        if endpoint not in self.scores.columns:
            print(f"Couldn't find endpoint {y} for plotting")
            return
            
        tyield, x, y = self.tyield_auc(
            endpoint=endpoint, threshold=threshold, window=window, extrapolate=extrapolate, scaffold=scaffold,
            basic_filter=chemistry_filters_basic, target_filter=chemistry_filter_target, return_trajectory=True
        )
        
        ax = sns.tsplot(x=x,y=y, palette='husl', label=label.capitalize())
        ax.set_ylabel("Yield")
        ax.set_xlabel("Index")
        ax.set_xticklabels([f'{int(x)/1000}k' for x in ax.get_xticks()])
        return ax
//  [python]
def plot_yield(self,
        endpoint, threshold, label=None, window=100, extrapolate=True, scaffold=False,
        chemistry_filters_basic=False, chemistry_filter_target=False
    ):
        """
        Plot the yield according to some endpoint and threshold, example, ratio of molecules with reward > 0.8.
        """
        if label is None:
            label = endpoint

        if endpoint not in self.scores.columns:
            print(f"Couldn't find endpoint {y} for plotting")
            return
            
        tyield, x, y = self.tyield_auc(
            endpoint=endpoint, threshold=threshold, window=window, extrapolate=extrapolate, scaffold=scaffold,
            basic_filter=chemistry_filters_basic, target_filter=chemistry_filter_target, return_trajectory=True
        )
        
        ax = sns.lineplot(x=x,y=y, palette='husl', label=label.capitalize())
        ax.set_ylabel("Yield")
        ax.set_xlabel("Index")
        ax.set_xticklabels([f'{int(x)/1000}k' for x in ax.get_xticks()])
        return ax
//  [python]
def plot_function():
    x_grid = np.linspace(0, 20, 100)
    y_grid = [example_criterion(x) for x in x_grid]
    fig, ax = plt.subplots()
    ax.plot(x_grid, y_grid)
    sns.despine()
    return fig, ax
//  [python]
def plot_function():
    x_grid = np.linspace(0, 20, 100)
    y_grid = [example_criterion(x) for x in x_grid]
    fig, ax = plt.subplots()
    sns.lineplot(x=x_grid, y=y_grid, ax=ax)
    sns.despine()
    return fig, ax
//  [python]
sns.set(rc={'figure.figsize':(12, 8)})
sns.set(font_scale = 2)
sns.set_style("whitegrid")

plt.rcParams.update({
    "text.usetex": True,
    "font.family": "serif",
    "font.serif": ["Times"],
    'axes.labelsize': 42,
    'axes.titlesize':42,
    'xtick.labelsize':40,
    'ytick.labelsize':40
})

# print(len(df[df["full_ann_num_parts"]==6]))
#B) plot only one graph
g = sns.pointplot(data=df, x="ann_num_parts", y="avg_probability", hue="full_ann_num_parts", palette=sns.color_palette("rocket", 6), join=True, ci=95)
//  [python]
sns.set(rc={'figure.figsize':(12, 8)})
sns.set(font_scale = 2)
sns.set_style("whitegrid")

plt.rcParams.update({
    "text.usetex": True,
    "font.family": "serif",
    "font.serif": ["Times"],
    'axes.labelsize': 42,
    'axes.titlesize':42,
    'xtick.labelsize':40,
    'ytick.labelsize':40
})

# print(len(df[df["full_ann_num_parts"]==6]))
#B) plot only one graph
g = sns.lineplot(data=df, x="ann_num_parts", y="avg_probability", hue="full_ann_num_parts", palette=sns.color_palette("rocket", 6), err_style="band")
//  [python]
def plot_run(paths, name, ax=None, x_key="steps", y_keys=["eval/loss"], window_size=1, max_x_value=None, **kwargs):
    for path in paths:
        assert LOG_FILE_NAME in os.listdir(path), "Did not find log file, found " + " ".join(os.listdir(path))
    for y_key in y_keys:
        xs, ys = [], []
        for path in paths:
            df = pd.read_csv(os.path.join(path, LOG_FILE_NAME))
            if y_key not in df:
                print("[research] WARNING: y_key was not in run, skipping plot", path)
            x, y = moving_avg(df[x_key], df[y_key], window_size=window_size)
            assert len(x) == len(y)
            if max_x_value is not None:
                y = y[x <= max_x_value] # need to set y value first
                x = x[x <= max_x_value]
            xs.append(x)
            ys.append(y)
        xs = np.concatenate(xs, axis=0)
        ys = np.concatenate(ys, axis=0)
        plot_df = pd.DataFrame({x_key: xs, y_key: ys})
        label = name + " " + y_key if len(y_keys) > 1 else name
        ci = "sd" if len(paths) > 0 else None
        sns.tsplot(ax=ax, x=xs, y=ys, condition=label, ci=ci, **kwargs)
//  [python]
def plot_run(paths, name, ax=None, x_key="steps", y_keys=["eval/loss"], window_size=1, max_x_value=None, **kwargs):
    for path in paths:
        assert LOG_FILE_NAME in os.listdir(path), "Did not find log file, found " + " ".join(os.listdir(path))
    for y_key in y_keys:
        xs, ys = [], []
        for path in paths:
            df = pd.read_csv(os.path.join(path, LOG_FILE_NAME))
            if y_key not in df:
                print("[research] WARNING: y_key was not in run, skipping plot", path)
            x, y = moving_avg(df[x_key], df[y_key], window_size=window_size)
            assert len(x) == len(y)
            if max_x_value is not None:
                y = y[x <= max_x_value] # need to set y value first
                x = x[x <= max_x_value]
            xs.append(x)
            ys.append(y)
        xs = np.concatenate(xs, axis=0)
        ys = np.concatenate(ys, axis=0)
        plot_df = pd.DataFrame({x_key: xs, y_key: ys})
        label = name + " " + y_key if len(y_keys) > 1 else name
        ci = "sd" if len(paths) > 0 else None
        sns.lineplot(ax=ax, x=x_key, y=y_key, data=plot_df, sort=True, ci=ci, label=label, **kwargs)
//  [python]
def task_create_stylized_algo_gif(produces, algorithm):
    plot_data = STYLIZED_ALGORITHMS[algorithm]()
    # repeat the last point to show it longer in the gif
    plot_data = plot_data + [plot_data[-1]] * 2

    @gif.frame
    def visualize_step(evaluated_x, new_x, aux_line=None, remark=None):
        fig, ax = plot_function()
        sns.rugplot(x=evaluated_x)
        ax.plot([new_x], [example_criterion(new_x)], marker="*")
        if aux_line is not None:
            plt.plot(aux_line["x"], aux_line["y"])
        if remark is not None:
            plt.subplots_adjust(bottom=0.25)
            plt.figtext(
                0.5,
                0.05,
                remark,
                multialignment="center",
                ha="center",
                wrap=True,
                fontsize=14,
                bbox={
                    "facecolor": "white",
                    "alpha": 0.5,
                    "pad": 5,
                    "edgecolor": "#ffffff00",
                },
            )

    frames = [visualize_step(**data) for data in plot_data]

    gif.save(frames, produces, duration=7.5, unit="s")
//  [python]
def task_create_stylized_algo_gif(produces, algorithm):
    plot_data = STYLIZED_ALGORITHMS[algorithm]()
    # repeat the last point to show it longer in the gif
    plot_data = plot_data + [plot_data[-1]] * 2

    @gif.frame
    def visualize_step(evaluated_x, new_x, aux_line=None, remark=None):
        fig, ax = plot_function()
        sns.rugplot(x=evaluated_x)
        ax.plot([new_x], [example_criterion(new_x)], marker="*")
        if aux_line is not None:
            sns.lineplot(x=aux_line["x"], y=aux_line["y"])
        if remark is not None:
            plt.subplots_adjust(bottom=0.25)
            plt.figtext(
                0.5,
                0.05,
                remark,
                multialignment="center",
                ha="center",
                wrap=True,
                fontsize=14,
                bbox={
                    "facecolor": "white",
                    "alpha": 0.5,
                    "pad": 5,
                    "edgecolor": "#ffffff00",
                },
            )

    frames = [visualize_step(**data) for data in plot_data]

    gif.save(frames, produces, duration=7.5, unit="s")
//  [python]
def regression_plot(df):
    print("Plotting...")
    xtitle = "Sequence Length (s)"
    # df = df.rename(dict(sequence_length=xtitle))
    df.loc[:, 'sequence_length'] /= 256
    # df.loc[:, 'Accuracy'] /= df.loc[:, 'Mask_pct']
    sns.pointplot(data=df, x='sequence_length', y="Accuracy", hue="Dataset", palette='pastel')
    plt.xscale('log')
    plt.xticks([20, 30, 40, 60])
    plt.xlabel(xtitle)
    plt.title("Contrastive Task vs. Sequence Length")
    plt.show()
    print("Done.")
//  [python]
def regression_plot(df):
    print("Plotting...")
    xtitle = "Sequence Length (s)"
    # df = df.rename(dict(sequence_length=xtitle))
    df.loc[:, 'sequence_length'] /= 256
    # df.loc[:, 'Accuracy'] /= df.loc[:, 'Mask_pct']
    sns.lineplot(data=df, x='sequence_length', y="Accuracy", hue="Dataset", palette='pastel')
    plt.xscale('log')
    plt.xticks([20, 30, 40, 60])
    plt.xlabel(xtitle)
    plt.title("Contrastive Task vs. Sequence Length")
    plt.show()
    print("Done.")
//  [python]
def line_plot(
    plots_folder,
    df,
    x,
    y,
    filename,
    font_scale=0.8,
    figsize=(4.8, 4.8),
):
    sns.set(font_scale=font_scale, style="whitegrid", rc={"figure.figsize": figsize})

    best_trial_num = df.loc[df["score"].idxmax()]["trial_num"]
    best_trial = df[df["trial_num"] == best_trial_num]
    worst_trial_num = df.loc[df["score"].idxmin()]["trial_num"]
    worst_trial = df[df["trial_num"] == worst_trial_num]

    sns.pointplot(data=df, x=x, y=y, ci="sd", join=True)
    sns.pointplot(data=best_trial, x=x, y=y, color="green", join=True)
    plot = sns.pointplot(data=worst_trial, x=x, y=y, color="red", join=True)
    fig = plot.get_figure()
    c_f.makedir_if_not_there(plots_folder)
    fig.savefig(
        os.path.join(plots_folder, f"{filename}.png"),
        bbox_inches="tight",
    )
    fig.clf()
//  [python]
def line_plot(
    plots_folder,
    df,
    x,
    y,
    filename,
    font_scale=0.8,
    figsize=(4.8, 4.8),
):
    sns.set(font_scale=font_scale, style="whitegrid", rc={"figure.figsize": figsize})

    best_trial_num = df.loc[df["score"].idxmax()]["trial_num"]
    best_trial = df[df["trial_num"] == best_trial_num]
    worst_trial_num = df.loc[df["score"].idxmin()]["trial_num"]
    worst_trial = df[df["trial_num"] == worst_trial_num]

    sns.lineplot(data=df, x=x, y=y, ci="sd")
    sns.lineplot(data=best_trial, x=x, y=y, color="green")
    plot = sns.lineplot(data=worst_trial, x=x, y=y, color="red")
    fig = plot.get_figure()
    c_f.makedir_if_not_there(plots_folder)
    fig.savefig(
        os.path.join(plots_folder, f"{filename}.png"),
        bbox_inches="tight",
    )
    fig.clf()
//  [python]
y_array = np.array([])
x_array = np.array([])
rs = np.random.RandomState(8)
for _ in range(15):
    x = np.linspace(0, 30 / 2, 30)
    y = np.sin(x) + rs.normal(0, 1.5) + rs.normal(0, .3, 30)
    y_array = np.append(y_array, y)
    x_array = np.append(x_array, x)

# Plot the average over replicates with confidence interval
s.lineplot(y=y_array, x=x_array)
//  [python]
y_array = np.array([])
x_array = np.array([])
rs = np.random.RandomState(8)
for _ in range(15):
    x = np.linspace(0, 30 / 2, 30)
    y = np.sin(x) + rs.normal(0, 1.5) + rs.normal(0, .3, 30)
    y_array = np.append(y_array, y)
    x_array = np.append(x_array, x)

# Plot the average over replicates with confidence interval
sns.lineplot(y=y_array, x=x_array)
//  [python]
def plot(
        self,
        controller_under_test: "Controller",
        results_df: pd.DataFrame,
        display_plots: bool = False,
    ) -> List[Tuple[str, figure]]:
        """
        Plot the results, and return the plot handles. Optionally
        display the plots.

        args:
            controller_under_test: the controller with which to run the experiment
            display_plots: defaults to False. If True, display the plots (blocks until
                           the user responds).
        returns: a list of tuples containing the name of each figure and the figure
                 object.
        """

        # Set the color scheme
        sns.set_theme(context="talk", style="white")

        # Plot the state trajectories
        fig, rollout_ax = plt.subplots(1, 1)
        fig.set_size_inches(9, 6)

        # Plot the rollout
        sns.pointplot(
            ax=rollout_ax,
            x="t",
            y="||x||",
            style="Parameters",
            hue="Simulation",
            data=results_df,
        )

        # Remove the legend -- too much clutter
        rollout_ax.legend([], [], frameon=False)

        fig_handle = ("Rollout (state space)", fig)

        if display_plots:
            plt.show()
            return []
        else:
            return [fig_handle]
//  [python]
def plot(
        self,
        controller_under_test: "Controller",
        results_df: pd.DataFrame,
        display_plots: bool = False,
    ) -> List[Tuple[str, figure]]:
        """
        Plot the results, and return the plot handles. Optionally
        display the plots.

        args:
            controller_under_test: the controller with which to run the experiment
            display_plots: defaults to False. If True, display the plots (blocks until
                           the user responds).
        returns: a list of tuples containing the name of each figure and the figure
                 object.
        """

        # Set the color scheme
        sns.set_theme(context="talk", style="white")

        # Plot the state trajectories
        fig, rollout_ax = plt.subplots(1, 1)
        fig.set_size_inches(9, 6)

        # Plot the rollout
        sns.lineplot(
            ax=rollout_ax,
            x="t",
            y="||x||",
            style="Parameters",
            hue="Simulation",
            data=results_df,
        )

        # Remove the legend -- too much clutter
        rollout_ax.legend([], [], frameon=False)

        fig_handle = ("Rollout (state space)", fig)

        if display_plots:
            plt.show()
            return []
        else:
            return [fig_handle]
//  [python]
def make_graph():
    geysers = (
        sns.load_dataset("geyser")
        .rename(
            columns={
                "duration": "Duration",
                "kind": "Kind",
                "waiting": "Waiting",
            }
        )
        .replace({"long": "Long", "short": "Short"})
    )
    fig, ax = plt.subplots(1, 3, figsize=(15, 5))
    # Hacky patched boxplot since seaborn overrides color options otherwise
    # sns.boxplot(x="Kind", y="Duration", data=tips, ax=ax[0])
    ax[0].boxplot(
        [
            geysers.loc[geysers["Kind"] == "Long", "Duration"].tolist(),
            geysers.loc[geysers["Kind"] == "Short", "Duration"].tolist(),
        ],
        vert=True,
        patch_artist=True,
        labels=geysers["Kind"].unique(),
    )
    sns.kdeplot(
        x="Waiting", y="Duration", hue="Kind", data=geysers, ax=ax[1], fill=True
    )
    sns.pointplot(x="Waiting", y="Duration", hue="Kind", data=geysers, ax=ax[2])
    plt.suptitle("Geysers")
    return fig, ax
//  [python]
def make_graph():
    geysers = (
        sns.load_dataset("geyser")
        .rename(
            columns={
                "duration": "Duration",
                "kind": "Kind",
                "waiting": "Waiting",
            }
        )
        .replace({"long": "Long", "short": "Short"})
    )
    fig, ax = plt.subplots(1, 3, figsize=(15, 5))
    # Hacky patched boxplot since seaborn overrides color options otherwise
    # sns.boxplot(x="Kind", y="Duration", data=tips, ax=ax[0])
    ax[0].boxplot(
        [
            geysers.loc[geysers["Kind"] == "Long", "Duration"].tolist(),
            geysers.loc[geysers["Kind"] == "Short", "Duration"].tolist(),
        ],
        vert=True,
        patch_artist=True,
        labels=geysers["Kind"].unique(),
    )
    sns.kdeplot(
        x="Waiting", y="Duration", hue="Kind", data=geysers, ax=ax[1], fill=True
    )
    sns.lineplot(x="Waiting", y="Duration", hue="Kind", data=geysers, ax=ax[2])
    plt.suptitle("Geysers")
    return fig, ax
//  [python]
linestyle_tuple = [
    ("loosely dotted", (0, (1, 10))),
    ("densely dotted", (0, (1, 1))),
    ("loosely dashed", (0, (5, 10))),
    ("densely dashed", (0, (5, 1))),
    ("loosely dashdotted", (0, (3, 10, 1, 10))),
    ("densely dashdotted", (0, (3, 1, 1, 1))),
    ("dashdotdotted", (0, (3, 5, 1, 5, 1, 5))),
    ("loosely dashdotdotted", (0, (3, 10, 1, 10, 1, 10))),
    ("densely dashdotdotted", (0, (3, 1, 1, 1, 1, 1))),
]
linestyles = linestyle_tuple + linestyle_str
deltas = [d for d in results["d"].unique() if not (np.isnan(d))]
fig, ax = plt.subplots()
for i, d in enumerate(deltas):
    cdf = results.loc[results["d"] == d]
    sns.tsplot(
        data=cdf,
        time="e",
        value="Performance",
        condition=f"delta={d}",
        linestyle=linestyles[::-1][i][1],
        ax=ax,
    )
//  [python]
linestyle_tuple = [
    ("loosely dotted", (0, (1, 10))),
    ("densely dotted", (0, (1, 1))),
    ("loosely dashed", (0, (5, 10))),
    ("densely dashed", (0, (5, 1))),
    ("loosely dashdotted", (0, (3, 10, 1, 10))),
    ("densely dashdotted", (0, (3, 1, 1, 1))),
    ("dashdotdotted", (0, (3, 5, 1, 5, 1, 5))),
    ("loosely dashdotdotted", (0, (3, 10, 1, 10, 1, 10))),
    ("densely dashdotdotted", (0, (3, 1, 1, 1, 1, 1))),
]
linestyles = linestyle_tuple + linestyle_str
deltas = [d for d in results["d"].unique() if not (np.isnan(d))]
fig, ax = plt.subplots()
for i, d in enumerate(deltas):
    cdf = results.loc[results["d"] == d]
    sns.lineplot(
        data=cdf,
        x="e",
        y="Performance",
        label=f"delta={d}",
        linestyle=linestyles[::-1][i][1],
        ax=ax,
    )
//  [python]
def generate_plot_data_base(path: str, data: pd.DataFrame, x_axis: str, y_axis: str, step=1):
    print(x_axis, y_axis)
    axis = sns.tsplot(x=x_axis, y=y_axis, condition='algorithm', data=data, ci=95, err_style="sd",
                        unit="trial",  interpolate=False)
    fig = axis.get_figure()
    fig.savefig(path)
    fig.clf()
//  [python]
def generate_plot_data_base(path: str, data: pd.DataFrame, x_axis: str, y_axis: str, step=1):
    print(x_axis, y_axis)
    axis = sns.lineplot(x=x_axis, y=y_axis, hue='algorithm', errorbar=("sd", 95),
                        hue_order=sorted(data['algorithm'].unique()), data=data)
    fig = axis.get_figure()
    fig.savefig(path)
    fig.clf()
//  [python]
def registration_correlation_coefficient_plot(x, y, out_path):
    """Plots the annotation registration normalised correlation coefficent at different scale and saves it 
    """
    plt.plot(x, y)
    plt.xlabel('Annotation Scale Factor')
    plt.ylabel('Max. Normalised Correlation Coefficient')
    plt.savefig(out_path, dpi=180)
    plt.close()
//  [python]
def registration_correlation_coefficient_plot(x, y, out_path):
    """Plots the annotation registration normalised correlation coefficent at different scale and saves it 
    """
    sns.lineplot(x=x, y=y)
    plt.xlabel('Annotation Scale Factor')
    plt.ylabel('Max. Normalised Correlation Coefficient')
    plt.savefig(out_path, dpi=180)
    plt.close()
//  [python]
fig, axes = plt.subplots(1, 3, figsize=(7, 1.2), dpi=300, sharey=False)


sns.lineplot(
    data=eval_rets.loc[
        (eval_rets['n_metrics'] == 2048) & 
        (eval_rets['n_failures'] == 100),
    ],
    x='n_instances',
    y='epoch_time',
    hue='gpu',
    ax=axes[0],
    palette="Blues",
)
//  [python]
def plot_nr_hits(input_csv, outfolder):
    matplotlib.rcParams.update({'font.size': 16})
    sns.set(font_scale=1.1)
    indata = pd.read_csv(input_csv,sep='\t')
    ax = sns.pointplot(x="ref_id", y="nr_hits", hue="method", data=indata, ci = "sd", hue_order= ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", "kmers"], join=True)
    plt.xlabel('SIRV')
    plt.ylabel('Number NAMs')
    plt.tick_params(rotation=90)
    ax.set_xticklabels(ax.get_xmajorticklabels())
    plt.tight_layout()
    plt.legend(loc='upper right', labels = ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", r'$k$-mers'])
    plt.savefig(os.path.join(outfolder, "plot_nr_hits.pdf"))
    plt.clf()
    plt.close()
//  [python]
def plot_nr_hits(input_csv, outfolder):
    matplotlib.rcParams.update({'font.size': 16})
    sns.set(font_scale=1.1)
    indata = pd.read_csv(input_csv,sep='\t')
    # ax = sns.barplot(x="ref_id", y="nr_hits", hue="method", data=indata,
    #                       hue_order= ["randstrobes", "kmers"])
    ax = sns.lineplot(x="ref_id", y="nr_hits", hue="method", ci = "sd", hue_order= ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", "kmers"], 
                          data=indata, markers=True)
    plt.xlabel('SIRV')
    plt.ylabel('Number NAMs')
    plt.tick_params(rotation=90)
    # ax.set_xticklabels(size = 10)
    ax.set_xticklabels(ax.get_xmajorticklabels())
    # plt.ylim(0, 1)
    plt.tight_layout()
    plt.legend(loc='upper right', labels = ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", r'$k$-mers'])
    # ax.set_ylabel("Fraction correct")
    # ax.set_xlabel("Exon size")
    # plt.savefig(os.path.join(outfolder, "plot_nr_hits.eps"))
    plt.savefig(os.path.join(outfolder, "plot_nr_hits.pdf"))
    plt.clf()
    plt.close()
//  [python]
def plot_coverage(input_csv, outfolder):
    matplotlib.rcParams.update({'font.size': 16})
    sns.set(font_scale=1.1)
    indata = pd.read_csv(input_csv,sep='\t')
    # ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
    #                 data=tips, palette="muted")
    ax = sns.pointplot(x="ref_id", y="coverage", hue="method", ci = "sd", hue_order= ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", "kmers"], 
                         data=indata, markers=True)
    # ax = sns.violinplot(x="ref_id", y="coverage", hue="method",
    #                       hue_order= ["randstrobes", "kmers"], data=indata)
    plt.xlabel('SIRV')
    plt.ylabel('Fraction covered')
    plt.tick_params(rotation=90)
    # ax.set_xticklabels(size = 10)
    ax.set_xticklabels(ax.get_xmajorticklabels())
    plt.ylim(0, 1)
    plt.tight_layout()
    plt.legend(loc='lower right', labels = ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", r'$k$-mers'])
    # ax.set_ylabel("Fraction correct")
    # ax.set_xlabel("Exon size")
    # plt.savefig(os.path.join(outfolder, "plot_coverage.eps"))
    plt.savefig(os.path.join(outfolder, "plot_coverage.pdf"))
    plt.clf()
    plt.close()
//  [python]
def plot_coverage(input_csv, outfolder):
    matplotlib.rcParams.update({'font.size': 16})
    sns.set(font_scale=1.1)
    indata = pd.read_csv(input_csv,sep='\t')
    # ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
    #                 data=tips, palette="muted")
    ax = sns.lineplot(x="ref_id", y="coverage", hue="method", ci = "sd", hue_order= ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", "kmers"], 
                         data=indata, markers=True)
    # ax = sns.violinplot(x="ref_id", y="coverage", hue="method",
    #                       hue_order= ["randstrobes", "kmers"], data=indata)
    plt.xlabel('SIRV')
    plt.ylabel('Fraction covered')
    plt.tick_params(rotation=90)
    # ax.set_xticklabels(size = 10)
    ax.set_xticklabels(ax.get_xmajorticklabels())
    plt.ylim(0, 1)
    plt.tight_layout()
    plt.legend(loc='lower right', labels = ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", r'$k$-mers'])
    # ax.set_ylabel("Fraction correct")
    # ax.set_xlabel("Exon size")
    # plt.savefig(os.path.join(outfolder, "plot_coverage.eps"))
    plt.savefig(os.path.join(outfolder, "plot_coverage.pdf"))
    plt.clf()
    plt.close()
//  [python]
def visualize_sentence(i, et_tokens, human_saliency, lm_saliency, outfile):
    print(et_tokens[i], human_saliency[i], lm_saliency[i])
    if i == 153:
        # hardcoded uppercasing for better looking plot
        tokens = ["Oh,", "Sherlock", "Holmes", "by", "all", "means."]
    else:
        if len(et_tokens[i]) == len(human_saliency[i]) == len(lm_saliency[i]):
            tokens = et_tokens[i]
        else:
            print("Mismatched tokenisation for sentence", i)

    human_data = pd.DataFrame({"Tokens": tokens, "Importance": human_saliency[i]})
    model_data = pd.DataFrame({"Tokens": tokens, "Importance": lm_saliency[i]})

    all_data = pd.concat([human_data.assign(dataset='Human'), model_data.assign(dataset='Model')])
    fig, ax = plt.subplots(figsize=(8, 4))
    mypalette = sns.diverging_palette(150, 275, s=80, l=55, n=2)
    sns.set(font_scale=1)
    sns.set_style("white")
    sns.pointplot(x="Tokens", y="Importance", data=all_data, hue="dataset", style="dataset", markers=["o", "o"],
                 dashes=[(3, 3), (3, 3)], palette=mypalette, join=True)
    handles, labels = ax.get_legend_handles_labels()
    ax.legend(handles=handles, labels=labels)
    plt.savefig(outfile)
    plt.close()
//  [python]
def visualize_sentence(i, et_tokens, human_saliency, lm_saliency, outfile):
    print(et_tokens[i], human_saliency[i], lm_saliency[i])
    if i == 153:
        # hardcoded uppercasing for better looking plot
        tokens = ["Oh,", "Sherlock", "Holmes", "by", "all", "means."]
    else:
        if len(et_tokens[i]) == len(human_saliency[i]) == len(lm_saliency[i]):
            tokens = et_tokens[i]
        else:
            print("Mismatched tokenisation for sentence", i)

    human_data = pd.DataFrame({"Tokens": tokens, "Importance": human_saliency[i]})
    model_data = pd.DataFrame({"Tokens": tokens, "Importance": lm_saliency[i]})

    all_data = pd.concat([human_data.assign(dataset='Human'), model_data.assign(dataset='Model')])
    fig, ax = plt.subplots(figsize=(8, 4))
    mypalette = sns.diverging_palette(150, 275, s=80, l=55, n=2)
    sns.set(font_scale=1)
    sns.set_style("white")
    sns.lineplot(x="Tokens", y="Importance", data=all_data, hue="dataset", style="dataset", markers=False,
                 dashes=[(3, 3), (3, 3)], palette=mypalette)
    sns.scatterplot(x="Tokens", y="Importance", data=all_data, hue="dataset", size="Importance", markers=["o", "o"],
                    legend=False, sizes=(50, 300), palette=mypalette)

    handles, labels = ax.get_legend_handles_labels()
    ax.legend(handles=handles, labels=labels)
    plt.savefig(outfile)
    plt.close()
//  [python]
def plot_normalized_match_length(input_csv, outfolder):
    matplotlib.rcParams.update({'font.size': 16})
    sns.set(font_scale=1.1)
    indata = pd.read_csv(input_csv,sep='\t')
    # ax = sns.barplot(x="ref_id", y="nr_hits", hue="method", data=indata,
    #                       hue_order= ["randstrobes", "kmers"])
    plt.tick_params(axis='x', which='minor', labelsize=7)
    ax = sns.pointplot(x="ref_id", y="normalized_match_length", hue="method", ci = "sd", hue_order= ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", "kmers"], 
                        data=indata, markers=True, join=True)
    plt.xlabel('SIRV')
    plt.ylabel('Normalized NAM length')
    plt.tick_params(rotation=90)
    # ax.set_xticklabels(size = 10)
    ax.set_xticklabels(ax.get_xmajorticklabels())
    plt.ylim(0, 1)
    plt.tight_layout()
    plt.legend(loc='upper left', labels = ["randstrobes-(3,10,20,70)", "randstrobes-(2,15,20,70)", "hybridstrobes-(3,10,20,70)", "hybridstrobes-(2,15,20,70)", "minstrobes-(3,10,20,70)", "minstrobes-(2,15,20,70)", r'$k$-mers'])
    # ax.set_ylabel("Fraction correct")
    # ax.set_xlabel("Exon size")
    # plt.savefig(os.path.join(outfolder, "plot_normalized_match_length.eps"))
    plt.savefig(os.path.join(outfolder, "plot_normalized_match_length.pdf"))
    plt.clf()
    plt.close()