Exemple #1
0
def whole_best(benchmark=None,
               data=None,
               title_kwargs=None,
               normalize_error=False,
               **kwargs):
    data = data if data is not None else retrieve_scores(benchmark)
    models = [model for model in all_models if model in data['model'].values]
    fig, ax = pyplot.subplots(figsize=(5, 4))
    ax.set_title(benchmark_label_replace[benchmark], **(title_kwargs or {}))
    ceiling, ceiling_err = get_ceiling(benchmark,
                                       which='both',
                                       normalize_scale=normalize_error)
    _plot_bars(ax,
               models=models,
               data=data,
               text_kwargs=dict(fontdict=dict(fontsize=6)),
               **kwargs)
    if is_iterable(ceiling_err
                   ) or not np.isnan(ceiling_err):  # no performance benchmarks
        ceiling_y = 1  # we already normalized so ceiling == 1
        xlim = ax.get_xlim()
        ax.plot([-50, +50], [ceiling_y, ceiling_y], color='gray')
        shaded_errorbar(x=[-50, +50],
                        y=np.array([ceiling_y, ceiling_y]),
                        error=([ceiling_err[0], ceiling_err[0]],
                               [ceiling_err[1], ceiling_err[1]]),
                        ax=ax,
                        alpha=0,
                        shaded_kwargs=dict(color='darkgray', alpha=.5))
        ax.set_xlim(xlim)
        ax.set_ylim(
            [-.05, max(1.05 + ceiling_err[-1],
                       max(data['score']) + .05)])
    ax.set_xticks([])
    ax.set_xticklabels([])
    ax.yaxis.set_major_locator(MultipleLocator(base=0.2))
    ax.yaxis.set_major_formatter(score_formatter)
    ax.spines['bottom'].set_position(('data', 0))
    ax.spines['bottom'].set_linewidth(0.75)
    savefig(fig, Path(__file__).parent / f'bars-{benchmark}')
Exemple #2
0
def shaded_errorbar(x,
                    y,
                    error,
                    ax=None,
                    shaded_kwargs=None,
                    vertical=False,
                    **kwargs):
    if (len(np.array(y).shape) == 1 and not is_iterable(error)) \
            or len(np.array(error).shape) == 1:  # symmetric error (only single vector)
        error_low, error_high = error, error
    else:  # asymmetric error
        assert len(error) == 2
        error = np.vectorize(lambda e: max(e, 0))(
            error)  # guard against negative values
        error_low, error_high = error
    shaded_kwargs = shaded_kwargs or {}
    shaded_kwargs = {**dict(linewidth=0.0), **shaded_kwargs}
    ax = ax or pyplot.gca()
    line = ax.plot(x, y, **kwargs)
    if not vertical:
        ax.fill_between(x, y - error_low, y + error_high, **shaded_kwargs)
    else:
        ax.fill_betweenx(y, x - error_low, x + error_high, **shaded_kwargs)
    return line
Exemple #3
0
def _determine_visual_degrees(visual_degrees, stimulus_set):
    if not visual_degrees:
        visual_degrees = stimulus_set['degrees']
    if not is_iterable(visual_degrees):
        visual_degrees = np.array([visual_degrees] * len(stimulus_set))
    return visual_degrees
def make_list(element):
    if not is_iterable(element) or isinstance(element, (str, bytes)):
        return [element]
    return element