Reputation: 1267
Is there a way to create stacked-grouped bar charts in the current version of bokeh?
Currently I'm attempting to create a list of tupled groupings to pass as an x-axis:
i.e.
from bokeh.io import show, output_file, curdoc
from bokeh.models import ColumnDataSource, HoverTool, FactorRange
from bokeh.plotting import figure
factors = [
("2017","jan"),("2017","feb"),("2017","mar"),
("2018",'jan'),("2018","feb"),("2018","mar")
]
data = {'factors' : factors,
'Tammy' : [2, 1, 4, 3, 2, 4],
'Jim' : [5, 3, 4, 2, 4, 6],
'Mike' : [3, 2, 4, 4, 5, 3]}
users=['Tammy','Jim','Mike']
source = ColumnDataSource(data=data)
p = figure(x_range=FactorRange(*factors), plot_height=350)
p.vbar_stack(users, x=factors, width=0.9)
curdoc().add_root(p)
It's not working all that great currently..
Keyword argument sequences for broadcasting must be the same length as stackers
Upvotes: 0
Views: 438
Reputation: 1267
this works
from bokeh.core.properties import value
from bokeh.io import show, output_file, curdoc
from bokeh.models import ColumnDataSource, HoverTool, FactorRange
from bokeh.plotting import figure
years = ["2015", "2016", "2017"]
colors = ["#c9d9d3", "#718dbf", "#e84d60"]
data = {'factors' : [("2017","jan"),("2017","feb"),("2018","jan")],
'Tammy' : [2, 1, 4],
'Jim' : [5, 3, 4],
'Mike' : [3, 2, 4]}
users=['Tammy','Jim','Mike']
source = ColumnDataSource(data=data)
p = figure(x_range=FactorRange(*factors), plot_height=350, )
p.vbar_stack(users, x='factors', width=0.9, source=source, color=colors)
p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.axis.minor_tick_line_color = None
p.outline_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"
curdoc().add_root(p)
Thanks for listening to me broadcasting for the past hour.
Upvotes: 1