Flask Hbar func

问题描述 投票:0回答:1

我正在使用bokeh和pandas开发flask应用程序,我想将下面的hbar脚本转换为函数,以便可以在类似的数据框中使用它,

这是我的代码

Top_five_all_types_bar_source = ColumnDataSource(Top_five_all_types)
Top_five_all_types_path = Top_five_all_types['con_path'].tolist()
Top_five_all_types_count = Top_five_all_types['Sub_Child_Incident_id']

f_Top_five_all_types= figure(
    y_range=Top_five_all_types_path,
    plot_width =1000,
    plot_height = 300,
    x_axis_label = 'Top Five',


)

f_Top_five_all_types.hbar(
    y='con_path',
    right='Sub_Child_Incident_id',
    left=0,
    height = 0.4,
    source= Top_five_all_types_bar_source
)

hover = HoverTool()
hover.tooltips = """
    <div>Path: @con_path</div>
    <div>Count: @Sub_Child_Incident_id</div>
    <div>Weight: @weight</div>
"""
f_Top_five_all_types.add_tools(hover)

Top_five_all_types_hbar_js, Top_five_all_types_hbar_div = components(f_Top_five_all_types)

我尝试了此功能,但未定义Top_five_all_types_hbar_js错误

def HBarChart (source,con_path_col,srs_col,weight, labels, script, div):

    top_five_source = ColumnDataSource(source)
    top_five_path_list = source[con_path_col].tolist()
    top_five_count = source[srs_col]

    f = figure(
    y_range=top_five_path_list,
    plot_width =1000,
    plot_height = 300,
    x_axis_label = labels,
    )

    f.hbar(
    y=con_path_col,
    right=srs_col,
    left=0,
    height = 0.4,
    source= top_five_source
    )

    hover = HoverTool()
    hover.tooltips = """
    <div>Path: @con_path_col</div>
    <div>Count: @srs_col</div>
    <div>Weight: @weight</div>
    """
    f.add_tools(hover)

    script, div = components(f)

    return script, div


Top_five_all_types_hbar = HBarChart (
    Top_five_all_types,
    'con_path',
    'Sub_Child_Incident_id',
    'weight',
    'Top Five',
    Top_five_all_types_hbar_js,
    Top_five_all_types_hbar_div
    )

结果应类似于下图Hbar Image

python pandas flask bokeh
1个回答
0
投票
def HBarChart (source,con_path_col,srs_col,weight, labels): ...
© www.soinside.com 2019 - 2024. All rights reserved.