有没有办法在当前版本的散景中创建堆叠分组条形图?
目前我正在尝试创建一个列组作为x轴传递的组合:
即
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)
目前效果并不好......
Keyword argument sequences for broadcasting must be the same length as stackers
答案 0 :(得分:1)
这是有效的
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)
感谢收听我过去一小时的广播。