コード例 #1
0
ファイル: plot.py プロジェクト: yurymalkov/ann-benchmarks
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()
コード例 #2
0
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()
コード例 #3
0
def create_plot(all_data, xn, yn, linestyle, j2_env, additional_label = "", plottype = "line"):
    xm, ym = (metrics[xn], metrics[yn])
    render_all_points = plottype == "bubble"
    plot_data = get_lines(all_data, xn, yn, render_all_points)
    latex_code = j2_env.get_template("latex.template").\
                    render(plot_data = plot_data, caption = get_plot_label(xm, ym),
                    xlabel = xm["description"], ylabel = ym["description"])
    plot_data = get_lines(all_data, xn, yn, render_all_points)
    button_label = hashlib.sha224((get_plot_label(xm, ym) +
                additional_label).encode("utf-8")).hexdigest()
    return j2_env.get_template("chartjs.template").\
            render(args = args, latex_code = latex_code, button_label = button_label,
                    data_points = plot_data,
                    xlabel = xm["description"], ylabel = ym["description"],
                    plottype = plottype, plot_label = get_plot_label(xm, ym),
                    label = additional_label, linestyle = linestyle,
                    render_all_points = render_all_points)
コード例 #4
0
def create_plot(all_data, xn, yn, linestyle, j2_env, additional_label="",
                plottype="line"):
    xm, ym = (metrics[xn], metrics[yn])
    render_all_points = plottype == "bubble"
    plot_data = get_lines(all_data, xn, yn, render_all_points)
    latex_code = j2_env.get_template("latex.template").\
        render(plot_data=plot_data, caption=get_plot_label(xm, ym),
               xlabel=xm["description"], ylabel=ym["description"])
    plot_data = get_lines(all_data, xn, yn, render_all_points)
    button_label = hashlib.sha224((get_plot_label(xm, ym) + additional_label)
                                  .encode("utf-8")).hexdigest()
    return j2_env.get_template("chartjs.template").\
        render(args=args, latex_code=latex_code, button_label=button_label,
               data_points=plot_data,
               xlabel=xm["description"], ylabel=ym["description"],
               plottype=plottype, plot_label=get_plot_label(xm, ym),
               label=additional_label, linestyle=linestyle,
               render_all_points=render_all_points)
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
def create_plot(ds, all_data, xn, yn, linestyle, additional_label = "", plottype = "line"):
    xm, ym = (metrics[xn], metrics[yn])
    output_str = """
        <h3>%(xlabel)s/%(ylabel)s</h3>
        <div id="%(xlabel)s%(ylabel)s%(label)s">
            <canvas id="chart%(xlabel)s%(ylabel)s%(label)s" width="800" height="600"></canvas>
            <script>
                var ctx = document.getElementById("chart%(xlabel)s%(ylabel)s%(label)s");
                var chart = new Chart(ctx, {
                    type: "%(plottype)s",
                    data: { datasets: [%(datapoints)s
                        ]},
                        options: {
                            responsive: false,
                            title:{
                                display:true,
                                text: '%(plotlabel)s'
                            },
                            scales: {
                                xAxes: [{
                                    display: true,
                                    type: 'linear',
                                    max: '1',
                                    position: 'bottom',
                                    scaleLabel: {
                                        display: true,
                                        labelString: ' %(xlabel)s   '
                                    }
                                }],
                                yAxes: [{
                                    display: true,
                                    type: 'logarithmic',
                                    scaleLabel: {
                                        display: true,
                                        labelString: ' %(ylabel)s '
                                    }
                                }]
                            }
                        }
                    });
                </script>
            </div>""" % { "id" : ds, "xlabel" :  xm["description"], "ylabel" : ym["description"], "plottype" : plottype,
                        "plotlabel" : get_plot_label(xm, ym),  "label": additional_label,
                        "datapoints" : create_data_points(all_data, xn, yn, linestyle, plottype == "bubble") }
    if args.latex:
        output_str += """
        <div class="row">
            <div class="col-md-4 text-center">
                <button type="button" id="button_%(buttonlabel)s" class="btn btn-default" >Toggle latex code</button>
            </div>
        </div>
        <script>
        $("#button_%(buttonlabel)s").click(function() {
            $("#plot_%(buttonlabel)s").toggle();
        });
        </script>
        <div id="plot_%(buttonlabel)s" style="display:none">
            <pre>
            %(latexcode)s
            </pre>
        </div>
        """ % {  "latexcode": get_latex_plot(all_data, xm, ym, plottype), "buttonlabel" : hashlib.sha224(get_plot_label(xm, ym) + additional_label).hexdigest() }
    return output_str
コード例 #8
0
def create_plot(ds, all_data, xn, yn, linestyle, additional_label = "", plottype = "line"):
    xm, ym = (metrics[xn], metrics[yn])
    output_str = """
        <h3>%(xlabel)s/%(ylabel)s</h3>
        <div id="%(xlabel)s%(ylabel)s%(label)s">
            <canvas id="chart%(xlabel)s%(ylabel)s%(label)s" width="800" height="600"></canvas>
            <script>
                var ctx = document.getElementById("chart%(xlabel)s%(ylabel)s%(label)s");
                var chart = new Chart(ctx, {
                    type: "%(plottype)s",
                    data: { datasets: [%(datapoints)s
                        ]},
                        options: {
                            responsive: false,
                            title:{
                                display:true,
                                text: '%(plotlabel)s'
                            },
                            scales: {
                                xAxes: [{
                                    display: true,
                                    type: 'linear',
                                    max: '1',
                                    position: 'bottom',
                                    scaleLabel: {
                                        display: true,
                                        labelString: ' %(xlabel)s   '
                                    }
                                }],
                                yAxes: [{
                                    display: true,
                                    type: 'logarithmic',
                                    scaleLabel: {
                                        display: true,
                                        labelString: ' %(ylabel)s '
                                    }
                                }]
                            }
                        }
                    });
                function pushOrConcat(base, toPush) {
                        if (toPush) {
                                if (Chart.helpers.isArray(toPush)) {
                                        // base = base.concat(toPush);
                                        Array.prototype.push.apply(base, toPush);
                                } else {
                                        base.push(toPush);
                                }
                        }

                        return base;
                }
                Chart.Tooltip.prototype.getFooter = function(tooltipItem, data) {
                    var me = this;
                    var callbacks = me._options.callbacks;
                    var item = tooltipItem[0];

                    var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
                    var footer = "Parameters: " + data.datasets[item.datasetIndex].data[item.index].label || '';
                    var afterFooter = callbacks.afterFooter.apply(me, arguments);

                    var lines = [];
                    lines = pushOrConcat(lines, beforeFooter);
                    lines = pushOrConcat(lines, footer);
                    lines = pushOrConcat(lines, afterFooter);

                    return lines;
                }

                </script>
            </div>""" % { "id" : ds, "xlabel" :  xm["description"], "ylabel" : ym["description"], "plottype" : plottype,
                        "plotlabel" : get_plot_label(xm, ym),  "label": additional_label,
                        "datapoints" : create_data_points(all_data, xn, yn, linestyle, plottype == "bubble") }
    if args.latex:
        output_str += """
        <div class="row">
            <div class="col-md-4 text-center">
                <button type="button" id="button_%(buttonlabel)s" class="btn btn-default" >Toggle latex code</button>
            </div>
        </div>
        <script>
        $("#button_%(buttonlabel)s").click(function() {
            $("#plot_%(buttonlabel)s").toggle();
        });
        </script>
        <div id="plot_%(buttonlabel)s" style="display:none">
            <pre>
            %(latexcode)s
            </pre>
        </div>
        """ % {  "latexcode": get_latex_plot(all_data, xm, ym, plottype), "buttonlabel" : hashlib.sha224(get_plot_label(xm, ym) + additional_label).hexdigest() }
    return output_str
コード例 #9
0
def create_plot(ds,
                all_data,
                xn,
                yn,
                linestyle,
                additional_label="",
                plottype="line"):
    xm, ym = (metrics[xn], metrics[yn])
    output_str = """
        <h3>%(xlabel)s/%(ylabel)s</h3>
        <div id="%(xlabel)s%(ylabel)s%(label)s">
            <canvas id="chart%(xlabel)s%(ylabel)s%(label)s" width="800" height="600"></canvas>
            <script>
                var ctx = document.getElementById("chart%(xlabel)s%(ylabel)s%(label)s");
                var chart = new Chart(ctx, {
                    type: "%(plottype)s",
                    data: { datasets: [%(datapoints)s
                        ]},
                        options: {
                            responsive: false,
                            title:{
                                display:true,
                                text: '%(plotlabel)s'
                            },
                            scales: {
                                xAxes: [{
                                    display: true,
                                    type: 'linear',
                                    max: '1',
                                    position: 'bottom',
                                    scaleLabel: {
                                        display: true,
                                        labelString: ' %(xlabel)s   '
                                    }
                                }],
                                yAxes: [{
                                    display: true,
                                    type: 'logarithmic',
                                    scaleLabel: {
                                        display: true,
                                        labelString: ' %(ylabel)s '
                                    }
                                }]
                            }
                        }
                    });
                function pushOrConcat(base, toPush) {
                        if (toPush) {
                                if (Chart.helpers.isArray(toPush)) {
                                        // base = base.concat(toPush);
                                        Array.prototype.push.apply(base, toPush);
                                } else {
                                        base.push(toPush);
                                }
                        }

                        return base;
                }
                Chart.Tooltip.prototype.getFooter = function(tooltipItem, data) {
                    var me = this;
                    var callbacks = me._options.callbacks;
                    var item = tooltipItem[0];

                    var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
                    var footer = "Parameters: " + data.datasets[item.datasetIndex].data[item.index].label || '';
                    var afterFooter = callbacks.afterFooter.apply(me, arguments);

                    var lines = [];
                    lines = pushOrConcat(lines, beforeFooter);
                    lines = pushOrConcat(lines, footer);
                    lines = pushOrConcat(lines, afterFooter);

                    return lines;
                }

                </script>
            </div>""" % {
        "id":
        ds,
        "xlabel":
        xm["description"],
        "ylabel":
        ym["description"],
        "plottype":
        plottype,
        "plotlabel":
        get_plot_label(xm, ym),
        "label":
        additional_label,
        "datapoints":
        create_data_points(all_data, xn, yn, linestyle, plottype == "bubble")
    }
    if args.latex:
        output_str += """
        <div class="row">
            <div class="col-md-4 text-center">
                <button type="button" id="button_%(buttonlabel)s" class="btn btn-default" >Toggle latex code</button>
            </div>
        </div>
        <script>
        $("#button_%(buttonlabel)s").click(function() {
            $("#plot_%(buttonlabel)s").toggle();
        });
        </script>
        <div id="plot_%(buttonlabel)s" style="display:none">
            <pre>
            %(latexcode)s
            </pre>
        </div>
        """ % {
            "latexcode":
            get_latex_plot(all_data, xm, ym, plottype),
            "buttonlabel":
            hashlib.sha224(get_plot_label(xm, ym) +
                           additional_label).hexdigest()
        }
    return output_str
コード例 #10
0
ファイル: plot.py プロジェクト: vdaas/ann-benchmarks
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()