def create_plot(all_data, raw, x_log, y_log, xn, yn, fn_out, linestyles): xm, ym = (metrics[xn], metrics[yn]) # Now generate each plot handles = [] labels = [] plt.figure(figsize=(12, 9)) for algo in sorted(all_data.keys(), key=lambda x: x.lower()): xs, ys, ls, axs, ays, als = create_pointset(all_data[algo], xn, yn) color, faded, linestyle, marker = linestyles[algo] handle, = plt.plot(xs, ys, '-', label=algo, color=color, ms=7, mew=3, lw=3, linestyle=linestyle, marker=marker) handles.append(handle) if raw: handle2, = plt.plot(axs, ays, '-', label=algo, color=faded, ms=5, mew=2, lw=2, linestyle=linestyle, marker=marker) labels.append(algo) if x_log: plt.gca().set_xscale('log') if y_log: plt.gca().set_yscale('log') plt.gca().set_title(get_plot_label(xm, ym)) plt.gca().set_ylabel(ym['description']) plt.gca().set_xlabel(xm['description']) box = plt.gca().get_position() # plt.gca().set_position([box.x0, box.y0, box.width * 0.8, box.height]) plt.gca().legend(handles, labels, loc='center left', bbox_to_anchor=(1, 0.5), prop={'size': 9}) plt.grid(b=True, which='major', color='0.65',linestyle='-') if 'lim' in xm: plt.xlim(xm['lim']) if 'lim' in ym: plt.ylim(ym['lim']) plt.savefig(fn_out, bbox_inches='tight') plt.close()
def create_data_points(all_data, xn, yn, linestyle, render_all_points): color_index = 0 html_str = "" for algo in sorted(all_data.keys(), key=lambda x: x.lower()): xs, ys, ls, axs, ays, als = create_pointset(algo, all_data, xn, yn) if render_all_points: xs, ys, ls = axs, ays, als # TODO Put this somewhere else # pretty print subprocess parameter settings. for i in range(len(ls)): if "Subprocess" in ls[i]: ls[i] = ls[i].split("(")[1].split("{")[1].split("}")[0].replace("'", "") html_str += """ { label: "%(algo)s", fill: false, pointStyle: "%(ps)s", borderColor: "%(color)s", data: [ """ % {"algo" : algo, "color" : linestyle[algo][0], "ps" : linestyle[algo][3] } for i in range(len(xs)): html_str += """ { x: %(x)s, y: %(y)s, label: "%(label)s" },""" % {"x" : str(xs[i]), "y" : str(ys[i]), "label" : ls[i] } html_str += """ ]},""" color_index += 1 return html_str
def create_plot(all_data, raw, x_log, y_log, xn, yn, fn_out, linestyles): xm, ym = (metrics[xn], metrics[yn]) # Now generate each plot handles = [] labels = [] plt.figure(figsize=(12, 9)) for algo in sorted(all_data.keys(), key=lambda x: x.lower()): xs, ys, ls, axs, ays, als = create_pointset(all_data[algo], xn, yn) color, faded, linestyle, marker = linestyles[algo] handle, = plt.plot(xs, ys, '-', label=algo, color=color, ms=7, mew=3, lw=3, linestyle=linestyle, marker=marker) handles.append(handle) if raw: handle2, = plt.plot(axs, ays, '-', label=algo, color=faded, ms=5, mew=2, lw=2, linestyle=linestyle, marker=marker) labels.append(algo) if x_log: plt.gca().set_xscale('log') if y_log: plt.gca().set_yscale('log') plt.gca().set_title(get_plot_label(xm, ym)) plt.gca().set_ylabel(ym['description']) plt.gca().set_xlabel(xm['description']) box = plt.gca().get_position() # plt.gca().set_position([box.x0, box.y0, box.width * 0.8, box.height]) plt.gca().legend(handles, labels, loc='center left', bbox_to_anchor=(1, 0.5), prop={'size': 9}) plt.grid(b=True, which='major', color='0.65',linestyle='-') if 'lim' in xm: plt.xlim(xm['lim']) if 'lim' in ym: plt.ylim(ym['lim']) plt.savefig(fn_out, bbox_inches='tight') plt.close()
def get_lines(all_data, xn, yn, render_all_points): """ For each algorithm run on a dataset, obtain its performance curve coords.""" plot_data = [] for algo in sorted(all_data.keys(), key=lambda x: x.lower()): xs, ys, ls, axs, ays, als = \ create_pointset(prepare_data(all_data[algo], xn, yn), xn, yn) if render_all_points: xs, ys, ls = axs, ays, als plot_data.append({ "name": algo, "coords" : zip(xs, ys), "labels" : ls, "scatter" : render_all_points}) return plot_data
def get_lines(all_data, xn, yn, render_all_points): """ For each algorithm run on a dataset, obtain its performance curve coords.""" plot_data = [] for algo in sorted(all_data.keys(), key=lambda x: x.lower()): xs, ys, ls, axs, ays, als = \ create_pointset(prepare_data(all_data[algo], xn, yn), xn, yn) if render_all_points: xs, ys, ls = axs, ays, als plot_data.append({"name": algo, "coords": zip(xs, ys), "labels": ls, "scatter": render_all_points}) return plot_data
def get_latex_plot(all_data, xm, ym, plottype): latex_str = """ \\begin{figure} \\centering \\begin{tikzpicture} \\begin{axis}[ xlabel={%(xlabel)s}, ylabel={%(ylabel)s}, ymode = log, yticklabel style={/pgf/number format/fixed, /pgf/number format/precision=3}, legend style = { anchor=west}, cycle list name = black white ] """ % { "xlabel": xm["description"], "ylabel": ym["description"] } color_index = 0 only_marks = "" if plottype == "bubble": only_marks = "[only marks]" for algo in sorted(all_data.keys(), key=lambda x: x.lower()): xs, ys, ls, axs, ays, als = create_pointset(algo, all_data, xn, yn) for i in range(len(ls)): if "Subprocess" in ls[i]: ls[i] = ls[i].split("(")[1].split("{")[1].split( "}")[0].replace("'", "") latex_str += """ \\addplot %s coordinates {""" % only_marks for i in range(len(xs)): latex_str += "(%s, %s)" % (str(xs[i]), str(ys[i])) latex_str += " };" latex_str += """ \\addlegendentry{%s}; """ % (algo) latex_str += """ \\end{axis} \\end{tikzpicture} \\caption{%(caption)s} \\label{} \\end{figure} """ % { "caption": get_plot_label(xm, ym) } return latex_str
def get_latex_plot(all_data, xm, ym, plottype): latex_str = """ \\begin{figure} \\centering \\begin{tikzpicture} \\begin{axis}[ xlabel={%(xlabel)s}, ylabel={%(ylabel)s}, ymode = log, yticklabel style={/pgf/number format/fixed, /pgf/number format/precision=3}, legend style = { anchor=west}, cycle list name = black white ] """ % {"xlabel" : xm["description"], "ylabel" : ym["description"] } color_index = 0 only_marks = "" if plottype == "bubble": only_marks = "[only marks]" for algo in sorted(all_data.keys(), key=lambda x: x.lower()): xs, ys, ls, axs, ays, als = create_pointset(algo, all_data, xn, yn) for i in range(len(ls)): if "Subprocess" in ls[i]: ls[i] = ls[i].split("(")[1].split("{")[1].split("}")[0].replace("'", "") latex_str += """ \\addplot %s coordinates {""" % only_marks for i in range(len(xs)): latex_str += "(%s, %s)" % (str(xs[i]), str(ys[i])) latex_str += " };" latex_str += """ \\addlegendentry{%s}; """ % (algo) latex_str += """ \\end{axis} \\end{tikzpicture} \\caption{%(caption)s} \\label{} \\end{figure} """ % {"caption" : get_plot_label(xm, ym)} return latex_str
def mean_y(algo): xs, ys, ls, axs, ays, als = create_pointset(all_data[algo], xn, yn) return -np.log(np.array(ys)).mean()
def create_plot(all_data, raw, x_scale, y_scale, xn, yn, fn_out, linestyles, batch): xm, ym = (metrics[xn], metrics[yn]) # Now generate each plot handles = [] labels = [] plt.figure(figsize=(12, 9)) # Sorting by mean y-value helps aligning plots with labels def mean_y(algo): xs, ys, ls, axs, ays, als = create_pointset(all_data[algo], xn, yn) return -np.log(np.array(ys)).mean() # Find range for logit x-scale min_x, max_x = 1, 0 for algo in sorted(all_data.keys(), key=mean_y): xs, ys, ls, axs, ays, als = create_pointset(all_data[algo], xn, yn) min_x = min([min_x] + [x for x in xs if x > 0]) max_x = max([max_x] + [x for x in xs if x < 1]) color, faded, linestyle, marker = linestyles[algo] handle, = plt.plot(xs, ys, '-', label=algo, color=color, ms=7, mew=3, lw=3, linestyle=linestyle, marker=marker) handles.append(handle) if raw: handle2, = plt.plot(axs, ays, '-', label=algo, color=faded, ms=5, mew=2, lw=2, linestyle=linestyle, marker=marker) labels.append(algo) ax = plt.gca() ax.set_ylabel(ym['description']) ax.set_xlabel(xm['description']) # Custom scales of the type --x-scale a3 if x_scale[0] == 'a': alpha = int(x_scale[1:]) fun = lambda x: 1 - (1 - x)**(1 / alpha) inv_fun = lambda x: 1 - (1 - x)**alpha ax.set_xscale('function', functions=(fun, inv_fun)) if alpha <= 3: ticks = [inv_fun(x) for x in np.arange(0, 1.2, .2)] plt.xticks(ticks) if alpha > 3: from matplotlib import ticker ax.xaxis.set_major_formatter(ticker.LogitFormatter()) #plt.xticks(ticker.LogitLocator().tick_values(min_x, max_x)) plt.xticks([0, 1 / 2, 1 - 1e-1, 1 - 1e-2, 1 - 1e-3, 1 - 1e-4, 1]) # Other x-scales else: ax.set_xscale(x_scale) ax.set_yscale(y_scale) ax.set_title(get_plot_label(xm, ym)) box = plt.gca().get_position() # plt.gca().set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax.legend(handles, labels, loc='center left', bbox_to_anchor=(1, 0.5), prop={'size': 9}) plt.grid(b=True, which='major', color='0.65', linestyle='-') plt.setp(ax.get_xminorticklabels(), visible=True) # Logit scale has to be a subset of (0,1) if 'lim' in xm and x_scale != 'logit': x0, x1 = xm['lim'] plt.xlim(max(x0, 0), min(x1, 1)) elif x_scale == 'logit': plt.xlim(min_x, max_x) if 'lim' in ym: plt.ylim(ym['lim']) # Workaround for bug https://github.com/matplotlib/matplotlib/issues/6789 ax.spines['bottom']._adjust_location() plt.savefig(fn_out, bbox_inches='tight') plt.close()