plotting.py 文件源码

python
阅读 45 收藏 0 点赞 0 评论 0

项目:numba-examples 作者: numba 项目源码 文件源码
def make_plot(results, title, xlabel, ylabel, baseline, ycolname, yaxis_format):
    p = plotting.figure(plot_width=WIDTH, plot_height=250, title=title,
        x_axis_label=xlabel, y_axis_label=ylabel,
        toolbar_location="above", tools='box_zoom,reset')

    legend_items = []

    baseline_times = [t * 1e6 for t in results[baseline]['times']]

    for i, (impl_name, impl_data) in enumerate(results.items()):
        color = IMPL_COLORS[i % len(IMPL_COLORS)]
        style = IMPL_STYLES[i % len(IMPL_STYLES)]

        data = dict(x=impl_data['x'])
        # convert to microseconds
        data['times'] = [t * 1e6 for t in impl_data['times']]
        data['name'] = [impl_name] * len(data['x'])
        data['speedup'] = [b/t for (t,b) in zip(data['times'], baseline_times)]
        # not this is items/sec
        data['throughput'] = [items/t for (t, items) in zip(impl_data['times'], impl_data['x'])]

        source = plotting.ColumnDataSource(data=data)
        line = p.line('x', ycolname, source=source,
            line_width=2, line_color=color, line_dash=style)
        marker = p.circle('x', ycolname, source=source,
            size=10, fill_color=color)
        legend_items.append( (impl_name, [line, marker]) )

    hover = HoverTool(
        tooltips=[
            ('implementation', '@name'),
            ('x', '@x{%1.0e}'),
            ('time per call', '@times{%1.1e} usec'),
            ('speedup', '@{speedup}{%1.1f}x'),
            ('throughput', '@{throughput}{%1.1e}'),
        ],
        formatters={
            'x': 'printf',
            'times': 'printf',
            'speedup': 'printf',
            'throughput': 'printf',
        }
    )
    p.add_tools(hover)
    p.xaxis[0].formatter = PrintfTickFormatter(format='%1.0e')
    p.yaxis[0].formatter = PrintfTickFormatter(format=yaxis_format)

    legend = Legend(items=legend_items, location=(0, -30))
    p.add_layout(legend, 'right')

    return p
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号