4

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.

Prateek
  • 429
  • 1
  • 7
  • 17

2 Answers2

4

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)
renzop
  • 1,194
  • 2
  • 12
  • 26
  • It does do both stacking and grouping now, but there are formatting limitations. Apparently bokeh doesn't allow legends to be shown on two columns. So the stacks all have the same color. I don't think this can be fixed though, I'll just add a tooltip for this. – Prateek Jan 12 '17 at 21:27
  • 2
    bokeh.charts has been deprecated, is there a way to created a nested stack bar chart? – machump May 02 '18 at 18:39
0

I know I'm late, but the example under stacking and grouping in the following article from the official bokeh documentation covers this:

https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html

Nht_e0
  • 140
  • 4
  • 15