Bokeh - Stacked and grouped charts

跟風遠走 提交于 2021-01-27 06:56:29

问题


Is it possible to create a plot in bokeh that is both stacked and grouped? Kinda like http://www.highcharts.com/demo/column-stacked-and-grouped/.

The dataset is something like this

   count     date  class    user
    39  2016/12/28    4   user1
    26  2016/12/28    4   user2
    3   2016/12/28    4   user2
    8   2016/12/28    4   user1
    1   2016/12/28    4   user1
    22  2016/12/28    4   user1
    26  2016/12/28    4   user2
    1   2016/12/28    4   user1
    7   2016/12/28    4   user2
    12  2016/12/28    4   user3
    23  2016/12/28    4   user3
    31  2016/12/28    4   user3
    2   2016/12/31    4   user1
    1   2016/12/31    4   user2
    27  2016/12/31    4   user2

What I want to do is visualize the counts by stacking across class and grouping across user with the label for x-axis being the dates.


回答1:


Yes you can. Assuming you have your data in a pandas dataframe (df).

Here is an example in the bokeh documentation: Grouping Bar plots

from bokeh.charts import Bar, output_file, show

p = Bar(df, label='date', values='count', stack='class',  group='user',
    )

output_file("bar.html")

show(p)


来源:https://stackoverflow.com/questions/41432613/bokeh-stacked-and-grouped-charts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!