benchmarks/scripts/plotter.py
def create_plot(title: str, xlabel: str, ylabel: str, domain: list, *data):
    """Creates and Saves a 'Spagetti plot' with the given title, horizontal
    label, vertical label, domain and functions (name and values) presented
    in the data array. Plot saved to constant SAVING_DIR/plot_name"""
    agg_data = {'x': domain}
    agg_data.update({fn[0]: fn[1]
                     for fn
                     in data})
    df = pd.DataFrame(agg_data)

    plt.clf()

    # Hardcoded to print ratios
    col_name = df.columns[1]
    if col_name[0:5] == "I2B_T" or col_name[0:6] == "I2B_DH":
        new_title = "Ratio " + title
        sns.set_palette(["#0D4F91", "#187F0D", "#421474"])
        is_o_plot = "dataset o" in title

        # Reference line
        plt.axhline(y=1, linewidth=1, color='red', alpha=1)

        # First ratio
        n1 = "Ratio " + col_name[4:]
        df[n1] = df.iloc[:, 1] / df.iloc[:, 2]
        plt.plot(df['x'], df[n1], marker='.',
                 linewidth=1, alpha=0.3 if is_o_plot else 1, label=n1)

        # Second ratio
        n2 = "Ratio " + df.columns[3][4:]
        df[n2] = df.iloc[:, 3] / df.iloc[:, 4]
        plt.plot(df['x'], df[n2], marker='.',
                 linewidth=1, alpha=0.3 if is_o_plot else 1, label=n2)

        # Third ratio
        if not is_o_plot:
            n3 = "Ratio " + df.columns[5][4:]
            df[n3] = df.iloc[:, 5] / df.iloc[:, 6]
            plt.plot(df['x'], df[n3], marker='.',
                     linewidth=1, alpha=1, label=n3)

        # Trend line
        if is_o_plot:
            trend = get_lists_moving_avg(
                [df[n1].values, df[n2].values], args.moving_avg)
            plt.plot(df['x'][args.moving_avg-1:], trend, marker='', linewidth=1,
                     alpha=1, color='black', label="Ratios moving average line")
        df = df.drop(n1, axis=1)
        df = df.drop(n2, axis=1)
        if not is_o_plot:
            df = df.drop(n3, axis=1)

        plt.legend(loc=4, ncol=2)
        plt.title(new_title, loc='left',
                  fontsize=12, fontweight=0, color='black')
        plt.xlabel(xlabel)
        plt.ylabel('I2B performance / IB performance')

        if not os.path.exists(SAVING_DIR):
            os.makedirs(SAVING_DIR)

        plt.savefig(SAVING_DIR + '/' + new_title + '.png')
        plt.clf()

    # sns.set_palette("RdYlBu", len(data))
    sns.set_palette(["#0D4F91", "#8EAFC9", "#187F0D",
                     "#91C763", "#421474", "#AA8CB8"])

    # multiple line plot
    for column in df.drop('x', axis=1):
        if str(column[0:2]) == "I2":
            plt.plot(df['x'], df[column], marker='.',
                     linewidth=1, alpha=1, label=column)
        else:
            plt.plot(df['x'], df[column], marker='p',
                     linewidth=1, alpha=1, label=column)

    plt.legend(loc=4, ncol=2)
    plt.title(title, loc='left',
              fontsize=12, fontweight=0, color='black')
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.gca().set_ylim(bottom=0)

    if not os.path.exists(SAVING_DIR):
        os.makedirs(SAVING_DIR)
    plt.savefig(SAVING_DIR + '/' + title + '.png')
Creates and Saves a 'Spagetti plot' with the given title, horizontal
    label, vertical label, domain and functions (name and values) presented
    in the data array. Plot saved to constant SAVING_DIR/plot_name
Creates and Saves a 'Spagetti plot' with the given title, horizontal
label, vertical label, domain and functions (name and values) presented
in the data array.
Creates and Saves a ' Spagetti plot ' with the given title horizontal label vertical label domain and functions ( name and values ) presented in the data array .
def create_plot(title: str, xlabel: str, ylabel: str, domain: list, *data):
    agg_data = {'x': domain}
    agg_data.update({fn[0]: fn[1]
                     for fn
                     in data})
    df = pd.DataFrame(agg_data)
    plt.clf()
    col_name = df.columns[1]
    if col_name[0:5] == "I2B_T" or col_name[0:6] == "I2B_DH":
        new_title = "Ratio " + title
        sns.set_palette(["#0D4F91", "#187F0D", "#421474"])
        is_o_plot = "dataset o" in title
        plt.axhline(y=1, linewidth=1, color='red', alpha=1)
        n1 = "Ratio " + col_name[4:]
        df[n1] = df.iloc[:, 1] / df.iloc[:, 2]
        plt.plot(df['x'], df[n1], marker='.',
                 linewidth=1, alpha=0.3 if is_o_plot else 1, label=n1)
        n2 = "Ratio " + df.columns[3][4:]
        df[n2] = df.iloc[:, 3] / df.iloc[:, 4]
        plt.plot(df['x'], df[n2], marker='.',
                 linewidth=1, alpha=0.3 if is_o_plot else 1, label=n2)
        if not is_o_plot:
            n3 = "Ratio " + df.columns[5][4:]
            df[n3] = df.iloc[:, 5] / df.iloc[:, 6]
            plt.plot(df['x'], df[n3], marker='.',
                     linewidth=1, alpha=1, label=n3)
        if is_o_plot:
            trend = get_lists_moving_avg(
                [df[n1].values, df[n2].values], args.moving_avg)
            plt.plot(df['x'][args.moving_avg-1:], trend, marker='', linewidth=1,
                     alpha=1, color='black', label="Ratios moving average line")
        df = df.drop(n1, axis=1)
        df = df.drop(n2, axis=1)
        if not is_o_plot:
            df = df.drop(n3, axis=1)
        plt.legend(loc=4, ncol=2)
        plt.title(new_title, loc='left',
                  fontsize=12, fontweight=0, color='black')
        plt.xlabel(xlabel)
        plt.ylabel('I2B performance / IB performance')
        if not os.path.exists(SAVING_DIR):
            os.makedirs(SAVING_DIR)
        plt.savefig(SAVING_DIR + '/' + new_title + '.png')
        plt.clf()
    sns.set_palette(["#0D4F91", "#8EAFC9", "#187F0D",
                     "#91C763", "#421474", "#AA8CB8"])
    for column in df.drop('x', axis=1):
        if str(column[0:2]) == "I2":
            plt.plot(df['x'], df[column], marker='.',
                     linewidth=1, alpha=1, label=column)
        else:
            plt.plot(df['x'], df[column], marker='p',
                     linewidth=1, alpha=1, label=column)
    plt.legend(loc=4, ncol=2)
    plt.title(title, loc='left',
              fontsize=12, fontweight=0, color='black')
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.gca().set_ylim(bottom=0)
    if not os.path.exists(SAVING_DIR):
        os.makedirs(SAVING_DIR)
    plt.savefig(SAVING_DIR + '/' + title + '.png')
def create_plot ( title : str , xlabel : str , ylabel : str , domain : list , * data ) : agg_data = { 'x' : domain } agg_data . update ( { fn [ 0 ] : fn [ 1 ] for fn in data } ) df = pd . DataFrame ( agg_data ) plt . clf ( ) col_name = df . columns [ 1 ] if col_name [ 0 : 5 ] == "I2B_T" or col_name [ 0 : 6 ] == "I2B_DH" : new_title = "Ratio " + title sns . set_palette ( [ "#0D4F91" , "#187F0D" , "#421474" ] ) is_o_plot = "dataset o" in title plt . axhline ( y = 1 , linewidth = 1 , color = 'red' , alpha = 1 ) n1 = "Ratio " + col_name [ 4 : ] df [ n1 ] = df . iloc [ : , 1 ] / df . iloc [ : , 2 ] plt . plot ( df [ 'x' ] , df [ n1 ] , marker = '.' , linewidth = 1 , alpha = 0.3 if is_o_plot else 1 , label = n1 ) n2 = "Ratio " + df . columns [ 3 ] [ 4 : ] df [ n2 ] = df . iloc [ : , 3 ] / df . iloc [ : , 4 ] plt . plot ( df [ 'x' ] , df [ n2 ] , marker = '.' , linewidth = 1 , alpha = 0.3 if is_o_plot else 1 , label = n2 ) if not is_o_plot : n3 = "Ratio " + df . columns [ 5 ] [ 4 : ] df [ n3 ] = df . iloc [ : , 5 ] / df . iloc [ : , 6 ] plt . plot ( df [ 'x' ] , df [ n3 ] , marker = '.' , linewidth = 1 , alpha = 1 , label = n3 ) if is_o_plot : trend = get_lists_moving_avg ( [ df [ n1 ] . values , df [ n2 ] . values ] , args . moving_avg ) plt . plot ( df [ 'x' ] [ args . moving_avg - 1 : ] , trend , marker = '' , linewidth = 1 , alpha = 1 , color = 'black' , label = "Ratios moving average line" ) df = df . drop ( n1 , axis = 1 ) df = df . drop ( n2 , axis = 1 ) if not is_o_plot : df = df . drop ( n3 , axis = 1 ) plt . legend ( loc = 4 , ncol = 2 ) plt . title ( new_title , loc = 'left' , fontsize = 12 , fontweight = 0 , color = 'black' ) plt . xlabel ( xlabel ) plt . ylabel ( 'I2B performance / IB performance' ) if not os . path . exists ( SAVING_DIR ) : os . makedirs ( SAVING_DIR ) plt . savefig ( SAVING_DIR + '/' + new_title + '.png' ) plt . clf ( ) sns . set_palette ( [ "#0D4F91" , "#8EAFC9" , "#187F0D" , "#91C763" , "#421474" , "#AA8CB8" ] ) for column in df . drop ( 'x' , axis = 1 ) : if str ( column [ 0 : 2 ] ) == "I2" : plt . plot ( df [ 'x' ] , df [ column ] , marker = '.' , linewidth = 1 , alpha = 1 , label = column ) else : plt . plot ( df [ 'x' ] , df [ column ] , marker = 'p' , linewidth = 1 , alpha = 1 , label = column ) plt . legend ( loc = 4 , ncol = 2 ) plt . title ( title , loc = 'left' , fontsize = 12 , fontweight = 0 , color = 'black' ) plt . xlabel ( xlabel ) plt . ylabel ( ylabel ) plt . gca ( ) . set_ylim ( bottom = 0 ) if not os . path . exists ( SAVING_DIR ) : os . makedirs ( SAVING_DIR ) plt . savefig ( SAVING_DIR + '/' + title + '.png' )
Creates and Saves a 'Spagetti plot' with the given title, horizontal
label, vertical label, domain and functions (name and values) presented
in the data array.
Creates and Saves a ' Spagetti plot ' with the given title horizontal label vertical label domain and functions ( name and values ) presented in the data array .
"""Creates and Saves a 'Spagetti plot' with the given title, horizontal
    label, vertical label, domain and functions (name and values) presented
    in the data array. Plot saved to constant SAVING_DIR/plot_name""" # Hardcoded to print ratios # Reference line # First ratio # Second ratio # Third ratio # Trend line # sns.set_palette("RdYlBu", len(data)) # multiple line plot
title
str
xlabel
str
ylabel
str
domain
list