data = {'FFCB' : ['D','I'],
'CS' : [0.966248, 0],
'FPSI' : [0.00264871, 0],
'SA' : [0, 0.114216],
'NA' : [0.0127895, 0.00567031],
'O' : [0.00552444, 0],
'FPSDA' : [0.00136219, 0],
'HDR' : [3.78387e-05, 0]}
我想在bokeh
中创建一个聚类条形图,这样条形图及其x
标签的值就会显示在工具提示中。此外,xaxis主要标签应显示在图例中。未显示xaxis主要标签。仅显示组标签。 xaxis子组标签是标签值('D'
,'I'
)。 xaxis主要标签是余额标签。 ('CS','FPSI','SA','NA','O','FPSDA','HDR')
。主要标签需要显示在图例上,因为它们在实际数据中很长(如图所示)。条形图的值应显示在工具提示中。
有谁能帮助我解决这个问题。请看图片。
谢谢
迈克尔
这应该做的工作(测试Bokeh v1.0.4)。如果您愿意,可以将图例方向更改为“垂直”。
from bokeh.core.properties import value
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource, HoverTool, CustomJS
from bokeh.plotting import figure
from bokeh.transform import dodge
from bokeh.palettes import Spectral6
data = {'FFCB' : ['D', 'I'],
'CS' : [0.013254, 0.01],
'FPSI' : [0.00264871, 0.02],
'SA' : [0.03, 0.114216],
'NA' : [0.0127895, 0.00567031],
'O' : [0.00552444, 0.03],
'FPSDA' : [0.00136219, 0.04],
'HDR' : [0.03, 0.05]}
source = ColumnDataSource(data = data)
p = figure(x_range = data['FFCB'], y_range = (0, 0.2), plot_width = 600, plot_height = 400, title = "Clustered bar chart", tools = '')
vbar1 = p.vbar(x = dodge('FFCB', -0.25, range = p.x_range), top = 'CS', width = 0.1, source = source,
color = Spectral6[0], legend = value("CS"))
hover_tool_vbar1 = HoverTool(tooltips = [('CS', '@CS{0.000}')], show_arrow = False, renderers = [vbar1])
vbar2 = p.vbar(x = dodge('FFCB', -0.15, range = p.x_range), top = 'FPSI', width = 0.1, source = source,
color = Spectral6[1], legend = value("FPSI"))
hover_tool_vbar2 = HoverTool(tooltips = [('FPSI', '@FPSI{0.000}')], show_arrow = False, renderers = [vbar2])
vbar3 = p.vbar(x = dodge('FFCB', -0.05, range = p.x_range), top = 'SA', width = 0.1, source = source,
color = Spectral6[2], legend = value("SA"))
hover_tool_vbar3 = HoverTool(tooltips = [('SA', '@SA{0.000}')], show_arrow = False, renderers = [vbar3])
vbar4 = p.vbar(x = dodge('FFCB', 0.05, range = p.x_range), top = 'NA', width = 0.1, source = source,
color = Spectral6[3], legend = value("NA"))
hover_tool_vbar4 = HoverTool(tooltips = [('NA', '@NA{0.000}')], show_arrow = False, renderers = [vbar4])
vbar5 = p.vbar(x = dodge('FFCB', 0.15, range = p.x_range), top = 'O', width = 0.1, source = source,
color = Spectral6[4], legend = value("O"))
hover_tool_vbar5 = HoverTool(tooltips = [('O', '@O{0.000}')], show_arrow = False, renderers = [vbar5])
vbar6 = p.vbar(x = dodge('FFCB', 0.25, range = p.x_range), top = 'HDR', width = 0.1, source = source,
color = Spectral6[5], legend = value("HDR"))
hover_tool_vbar6 = HoverTool(tooltips = [('HDR', '@HDR{0.000}')], show_arrow = False, renderers = [vbar6])
p.x_range.range_padding = 0.2
p.xgrid.grid_line_color = None
p.legend.location = "top_left"
p.legend.click_policy = 'hide'
p.legend.orientation = "horizontal"
p.add_tools(hover_tool_vbar1, hover_tool_vbar2, hover_tool_vbar3, hover_tool_vbar4, hover_tool_vbar5, hover_tool_vbar6)
show(p)
结果: