使用PythonBokeh中的循环动态创建不同列值的条形图

2024-09-29 21:51:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个列名为“Type”的数据框,它获取分类值,如a、B、C等。此列动态获取值,不同/唯一的值可以随时更改。你知道吗

Eg. Data set Image:

enter image description here

我想运行以下代码为“Type”列中的每个不同值动态创建条形图(使用Bokeh可视化库)。你知道吗

下面是我当前正在运行的,通过手动切片“Type”中每个值的数据

Lets say "df" is name of the data frame containing rows only for "Type" =A

source_df  = ColumnDataSource(df)

TOOLTIPS = [ ("Month : ", "@Month"),
             (" Aggregated Metric1 : ", "@Metric1{ 0.0 a}") ]

hover = HoverTool()
hover.tooltips =  TOOLTIPS

pYOY = figure(x_range=df['Month'], y_range=(0, 100000), plot_height=300,plot_width=1000, 
           toolbar_location=None, tools = "box_select, box_zoom , wheel_zoom,reset")

pYOY.vbar(x=dodge('Month', 0, range=pYOY.x_range), top='Metric1', width=0.2, source=source_df,
       color="#c9d9d3", legend=("# Rev"))

pYOY.tools.append(hover)
pYOY.yaxis.axis_label = "Rev"
pYOY.xaxis.axis_label = "Month"

非常感谢您的帮助!


Tags: 数据boxsourcedfplottyperangewidth

热门问题