(times, methods, metric="mean", labels=None, linewidth=3, fontsize=20,
                                   x_label="Error", y_label="Time", log_y=False, log_x=False, plot_legend=True,
                                   title="", legend_loc=0, percentiles=(5, 95), colors=None, std_scale=1,
                                   markersize=15, markevery=1)
return plt
Plot performance over time

    Example:
    ----------------------------
    x = np.array([[1, 2, 3, 4, 5], [1, 2, 3, 4]])
    method_1 = np.array([[1,4,5,2], [3,4,3,6] , [2,5,5,8]])
    method_2 = np.array([[8,7,5,9], [7,3,9,1] , [3,2,9,4]])
    method_3 = np.array([[10,13,9,11], [9,12,10,10] , [11,14,18,6]])
    methods = [method_1, method_2, method_3]
    plot = plot_optimization_trajectories(x, methods)
    plot.show()
Plot performance over time
Plot performance over time
def plot_optimization_trajectories(times, methods, metric="mean", labels=None, linewidth=3, fontsize=20,
                                   x_label="Error", y_label="Time", log_y=False, log_x=False, plot_legend=True,
                                   title="", legend_loc=0, percentiles=(5, 95), colors=None, std_scale=1,
                                   markersize=15, markevery=1):
    """
    Plot performance over time

    Example:
    ----------------------------
    x = np.array([[1, 2, 3, 4, 5], [1, 2, 3, 4]])
    method_1 = np.array([[1,4,5,2], [3,4,3,6] , [2,5,5,8]])
    method_2 = np.array([[8,7,5,9], [7,3,9,1] , [3,2,9,4]])
    method_3 = np.array([[10,13,9,11], [9,12,10,10] , [11,14,18,6]])
    methods = [method_1, method_2, method_3]
    plot = plot_optimization_trajectories(x, methods)
    plot.show()

    """

    if labels is None:
        labels = ["Method-%d" % i for i in range(len(methods))]

    styles = ["o", "D", "s", ">", "<", "^", "v", "*", "*", "."]

    if colors is None:
        colors = ["blue", "green", "purple", "darkorange",
                  "red", "palevioletred", "lightseagreen", "brown", "black"]

    for index, method in enumerate(methods):
        style = styles[index % len(styles)]
        color = colors[index % len(colors)]
        if metric == "median":
            plt.plot(times[index], np.median(method, axis=0), label=labels[index],
                     linewidth=linewidth, marker=style, color=color, markevery=markevery,
                     markersize=markersize, markeredgecolor=color, markerfacecolor='none', markeredgewidth=5)
        elif metric == "mean":
            plt.plot(times[index], np.mean(method, axis=0), label=labels[index],
                     linewidth=linewidth, marker=style, color=color, markevery=markevery,
                     markersize=markersize, markeredgecolor=color, markerfacecolor='none', markeredgewidth=5)
        elif metric == "median_percentiles":
            plt.plot(times[index], np.median(method, axis=0), label=labels[index],
                     linewidth=linewidth, marker=style, color=color, markevery=markevery,
                     markersize=markersize, markeredgecolor=color, markerfacecolor='none', markeredgewidth=5)
            plt.fill_between(times[index], np.percentile(method, percentiles[0], axis=0),
                             np.percentile(method, percentiles[1], axis=0),
                             color=color, alpha=0.2)
        elif metric == "mean_std":
            plt.plot(times[index], np.mean(method, axis=0), label=labels[index],
                     linewidth=linewidth, marker=style, color=color, markevery=markevery,
                     markersize=markersize, markeredgecolor=color, markerfacecolor='none', markeredgewidth=5)
            plt.fill_between(times[index], np.mean(method, axis=0) + std_scale * np.std(method, axis=0),
                             np.mean(method, axis=0) - std_scale * np.std(method, axis=0),
                             linewidth=linewidth, color=color, alpha=0.2)
        elif metric == "mean_sem":
            plt.plot(times[index], np.mean(method, axis=0), label=labels[index],
                     linewidth=linewidth, marker=style, color=color, markevery=markevery,
                     markersize=markersize, markeredgecolor=color, markerfacecolor='none', markeredgewidth=5)
            plt.fill_between(times[index], np.mean(method, axis=0) + std_scale * stats.sem(method, axis=0),
                             np.mean(method, axis=0) - std_scale * stats.sem(method, axis=0),
                             linewidth=linewidth, color=color, alpha=0.2)
        else:
            raise ValueError("Metric does not exist!")

        if plot_legend:
            plt.legend(loc=legend_loc, fancybox=True, framealpha=1, frameon=True, fontsize=fontsize)
        plt.xlabel(x_label, fontsize=fontsize)
        plt.ylabel(y_label, fontsize=fontsize)
        if log_y:
            plt.yscale("log")
        if log_x:
            plt.xscale("log")
        plt.grid(True, which='both', ls="-", alpha=1)
        plt.title(title, fontsize=fontsize)
    return plt
def plot_optimization_trajectories ( times , methods , metric = "mean" , labels = None , linewidth = 3 , fontsize = 20 , x_label = "Error" , y_label = "Time" , log_y = False , log_x = False , plot_legend = True , title = "" , legend_loc = 0 , percentiles = ( 5 , 95 ) , colors = None , std_scale = 1 , markersize = 15 , markevery = 1 ) : if labels is None : labels = [ "Method-%d" % i for i in range ( len ( methods ) ) ] styles = [ "o" , "D" , "s" , ">" , "<" , "^" , "v" , "*" , "*" , "." ] if colors is None : colors = [ "blue" , "green" , "purple" , "darkorange" , "red" , "palevioletred" , "lightseagreen" , "brown" , "black" ] for index , method in enumerate ( methods ) : style = styles [ index % len ( styles ) ] color = colors [ index % len ( colors ) ] if metric == "median" : plt . plot ( times [ index ] , np . median ( method , axis = 0 ) , label = labels [ index ] , linewidth = linewidth , marker = style , color = color , markevery = markevery , markersize = markersize , markeredgecolor = color , markerfacecolor = 'none' , markeredgewidth = 5 ) elif metric == "mean" : plt . plot ( times [ index ] , np . mean ( method , axis = 0 ) , label = labels [ index ] , linewidth = linewidth , marker = style , color = color , markevery = markevery , markersize = markersize , markeredgecolor = color , markerfacecolor = 'none' , markeredgewidth = 5 ) elif metric == "median_percentiles" : plt . plot ( times [ index ] , np . median ( method , axis = 0 ) , label = labels [ index ] , linewidth = linewidth , marker = style , color = color , markevery = markevery , markersize = markersize , markeredgecolor = color , markerfacecolor = 'none' , markeredgewidth = 5 ) plt . fill_between ( times [ index ] , np . percentile ( method , percentiles [ 0 ] , axis = 0 ) , np . percentile ( method , percentiles [ 1 ] , axis = 0 ) , color = color , alpha = 0.2 ) elif metric == "mean_std" : plt . plot ( times [ index ] , np . mean ( method , axis = 0 ) , label = labels [ index ] , linewidth = linewidth , marker = style , color = color , markevery = markevery , markersize = markersize , markeredgecolor = color , markerfacecolor = 'none' , markeredgewidth = 5 ) plt . fill_between ( times [ index ] , np . mean ( method , axis = 0 ) + std_scale * np . std ( method , axis = 0 ) , np . mean ( method , axis = 0 ) - std_scale * np . std ( method , axis = 0 ) , linewidth = linewidth , color = color , alpha = 0.2 ) elif metric == "mean_sem" : plt . plot ( times [ index ] , np . mean ( method , axis = 0 ) , label = labels [ index ] , linewidth = linewidth , marker = style , color = color , markevery = markevery , markersize = markersize , markeredgecolor = color , markerfacecolor = 'none' , markeredgewidth = 5 ) plt . fill_between ( times [ index ] , np . mean ( method , axis = 0 ) + std_scale * stats . sem ( method , axis = 0 ) , np . mean ( method , axis = 0 ) - std_scale * stats . sem ( method , axis = 0 ) , linewidth = linewidth , color = color , alpha = 0.2 ) else : raise ValueError ( "Metric does not exist!" ) if plot_legend : plt . legend ( loc = legend_loc , fancybox = True , framealpha = 1 , frameon = True , fontsize = fontsize ) plt . xlabel ( x_label , fontsize = fontsize ) plt . ylabel ( y_label , fontsize = fontsize ) if log_y : plt . yscale ( "log" ) if log_x : plt . xscale ( "log" ) plt . grid ( True , which = 'both' , ls = "-" , alpha = 1 ) plt . title ( title , fontsize = fontsize ) return plt