代码之家  ›  专栏  ›  技术社区  ›  Istvan

如何用Bokeh用箱线图绘制分类数据?

  •  0
  • Istvan  · 技术社区  · 7 年前

    df_times[:5]
        0   1   2   3   4
    0   211.635771  45.411404   17.134416   20.062214   185.544333
    1   234.500053  49.166657   17.052492   17.056290   205.531887
    2   234.224389  49.342572   17.868082   15.981429   193.489293
    3   221.880990  47.189842   17.054071   17.052869   198.318657
    4   223.811611  49.991753   17.052005   17.590466   219.541593
    

    图纸代码如下:

    colors        = ["red", "olive", "darkred", "goldenrod", "skyblue", "orange", "salmon"]
    charts_times = figure(plot_width=900, plot_height=350, title='Query Runtime')
    base, lower, upper, stds = [], [], [], []
    for i, table_name in enumerate([x[26:] for x in tables_to_be_analyzed]):
        run_time = df_times[i]
        run_time_mean = run_time.mean()
        run_time_std = run_time.std()
        stds.append(run_time_std)
        lower.append(run_time_mean - run_time_std)
        upper.append(run_time_mean + run_time_std)
        base.append(table_name)
        color = colors[i % len(colors)]
        charts_times.circle(x=table_name, y=run_time, color=color, size=6)
    
    charts_times.title.text = 'Query time ' + ' std: ' + str([round(x,1) for x in stds])
    source_times = ColumnDataSource(data=dict(base=base, lower=lower, upper=upper))
    charts_times.add_layout(
        Whisker(
            source=source_times, base="base", upper="upper", 
            lower="lower", line_width=1.5))
    show(charts_times)
    

    唯一的问题是,我不知道如何使用箱线图获得分类数据,因为bokeh只是抛出了一个错误:

    ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: orig_parquet_0 [renderer: GlyphRenderer(id='f3703748-b7f9-43f6-807c-a8a24bdaab32', ...)]
    ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: test_orc_opt_3 [renderer: GlyphRenderer(id='b86d8724-ff66-45ac-8a09-eaa70cadf348', ...)]
    ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: test_orc_opt_4 [renderer: GlyphRenderer(id='ee5f644e-b334-4bce-8184-9f7d8da8bba1', ...)]
    ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: test_orc_opt_6 [renderer: GlyphRenderer(id='55eb8c19-344f-4010-b254-222330b76203', ...)]
    ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name: test_parquet_opt_7 [renderer: GlyphRenderer(id='81ad57e4-4e01-4762-9a6e-0ce57cb51dd7', ...)]
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   bigreddot    7 年前

    传递列的名称 x :

    charts_times.circle(x=table_name, ...)
    

    但你还没有创建和传递任何 ColumnDataSource 作为 source circle . 您需要创建一个列名为 "orig_parquet_0"

    p.circle(x="colname", y=[1,2,3,...], # not possible
    

    如果某个glyphs的任何数据是从CDS中“按名称”引用的,那么 全部的

    p.circle(x="xname", y="yname", source=source)
    

    或者,可以将所有数据作为文本数组或列表传递,而不传递 来源 根本(你就是不能混搭):

    p.circle(x=[1,2,..], y=[4,5,...])  # also OK