Exemple #1
0
def _search_plot_cmd(
        path, y_field, x_field, groupby, spread_measure,
        style, do_legend=False, **axes_kwargs):

    path = process_path(path)
    print("Plotting searches stored at {}.".format(path))

    search = HyperSearch(path)

    with plt.style.context(style):
        ax = plt.axes(xlabel=x_field, ylabel=y_field, **axes_kwargs)

        dist = search.objects.load_object('metadata', 'dist')
        dist = Config(dist)

        df = search.extract_summary_data()

        groups = sorted(df.groupby(groupby))

        colours = plt.rcParams['axes.prop_cycle'].by_key()['color']

        legend = []

        for i, (k, _df) in enumerate(groups):
            values = list(_df.groupby(x_field))
            x = [v[0] for v in values]
            ys = [v[1][y_field] for v in values]

            y = [_y.mean() for _y in ys]

            if spread_measure == 'std_dev':
                y_upper = y_lower = [_y.std() for _y in ys]
            elif spread_measure == 'conf_int':
                conf_int = [confidence_interval(_y.values, 0.95) for _y in ys]
                y_lower = y - np.array([ci[0] for ci in conf_int])
                y_upper = np.array([ci[1] for ci in conf_int]) - y
            elif spread_measure == 'std_err':
                y_upper = y_lower = [standard_error(_y.values) for _y in ys]
            else:
                raise Exception("NotImplemented")

            yerr = np.vstack((y_lower, y_upper))

            c = colours[i % len(colours)]

            ax.semilogx(x, y, c=c, basex=2)
            handle = ax.errorbar(x, y, yerr=yerr, c=c)
            label = "{} = {}".format(groupby, k)

            legend.append((handle, label))

        if do_legend:
            handles, labels = zip(*legend)
            ax.legend(
                handles, labels, loc='center left',
                bbox_to_anchor=(1.05, 0.5), ncol=1)

        # plt.subplots_adjust(
        #     left=0.09, bottom=0.13, right=0.7, top=0.93, wspace=0.05, hspace=0.18)

    filename = "value_plot.pdf"
    print("Saving plot as {}".format(filename))
    plt.savefig(filename)
Exemple #2
0
def ci95(ys):
    conf_int = [confidence_interval(_y, 0.95) for _y in ys]
    y = ys.mean(axis=1)
    y_lower = y - np.array([ci[0] for ci in conf_int])
    y_upper = np.array([ci[1] for ci in conf_int]) - y
    return y_upper, y_lower