analyze.py 文件源码

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

项目:perfume 作者: leifwalsh 项目源码 文件源码
def cumulative_quantiles_plot(samples, plot_width=960, plot_height=480,
                              show_samples=True):
    '''Plots the cumulative quantiles along with a scatter plot of
    observations.'''
    plot = bp.figure(plot_width=960, plot_height=480)

    names = samples.columns.levels[0]
    _colors = {name: color
               for name, color in zip(names, colors.colors(len(names)))}

    def draw(group):
        name = group.columns[0][0]
        color = _colors[name]
        group.columns = group.columns.droplevel(0)
        group = group.dropna()
        quantile_source = bm.ColumnDataSource(
            pd.DataFrame(
                data={'lower': group['25%'], 'upper': group['75%']},
                index=group.index).dropna().reset_index())
        extreme_source = bm.ColumnDataSource(
            pd.DataFrame(
                data={'lower': group['min'], 'upper': group['max']},
                index=group.index).dropna().reset_index())
        plot.line(group.index, group['50%'], line_color=color, legend=name)
        plot.add_layout(bm.Band(base='time',
                                lower='lower',
                                upper='upper',
                                source=quantile_source,
                                fill_color=color, fill_alpha=0.2))
        plot.add_layout(bm.Band(base='time',
                                lower='lower',
                                upper='upper',
                                source=extreme_source,
                                fill_color=color, fill_alpha=0.025))
        plot.line('time', 'lower', line_color=color, alpha=0.5,
                  source=extreme_source)
        plot.line('time', 'upper', line_color=color, alpha=0.5,
                  source=extreme_source)
    cumulative_quantiles(samples).groupby(axis=1, level=0).apply(draw)

    if show_samples:
        def scatter(group):
            name = group.columns[0][0]
            color = _colors[name]
            group = isolate(group)
            t = timings(group).set_index(group.iloc[:, 1])
            t.index.name = 'time'
            t.columns = ['value']
            source = bm.ColumnDataSource(t.reset_index())
            plot.circle(x='time', y='value', source=source, color=color,
                        size=1, alpha=0.5)
        samples.groupby(axis=1, level=0).apply(scatter)

    bi.show(plot)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号