【发布时间】:2018-06-19 21:55:30
【问题描述】:
所以我基本上遵循了散景文档网站上关于处理分类数据的示例:
https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html
最终我得到了这段代码(我简化了一点):
# dictionary with data for making a figure
data = {'continents' : continents,
'2016' : list2016,
'2017' : list2017,
'2018' : list2018 }
source = ColumnDataSource(data=data)
p = figure(x_range=continents, y_range=(0, 450), plot_height=250, title="University count per continent per year",
toolbar_location=None, tools="")
p.vbar(x=dodge('continents', -0.25, range=p.x_range), top='2016', width=0.2, source=source,
color="#c9d9d3", legend=value("2016"))
p.vbar(x=dodge('continents', 0.0, range=p.x_range), top='2017', width=0.2, source=source,
color="#718dbf", legend=value("2017"))
p.vbar(x=dodge('continents', 0.25, range=p.x_range), top='2018', width=0.2, source=source,
color="#e84d60", legend=value("2018"))
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.legend.location = "top_right"
p.legend.orientation = "horizontal"
其中数据列有 4 个键,大洲是“类别”,2016、2017 和 2018 是与大洲列表中的每个大洲对应的值列表。比如:
continents = ["Africa", "Europe"]
list2016 = ["1", "3"]
list2017 = ["4", "2"]
list2018 = ["14", "3"]
所以这基本上是非洲在 2016 年、2017 年和 2018 年分别有 1 件、4 件和 14 件东西。现在我想做的是在这些不同的垂直条上添加悬停,这样如果我悬停在某个条上,它会给我那个年份/大陆的数字计数。这可能吗?
【问题讨论】: