【发布时间】:2021-03-29 10:25:55
【问题描述】:
我有一个多数据条形图,希望在悬停时显示每个条形的最大值。我已经更改了几次代码,但从未成功... 这是代码: '''
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Panel, Tabs
from bokeh.models.tools import HoverTool
modalites = ['0-510','511-1002', '1003-2167', '>2168']
valeur1 = list(tables.loc[0])
valeur2 = list(tables.loc[1])
valeur3 = list(tables_2.loc[0])
valeur4 = list(tables_2.loc[1])
source1 = ColumnDataSource({'x' : modalites, 'valeur 1' : valeur1, 'valeur 2' : valeur2})
source2 = ColumnDataSource({'x' : modalites, 'valeur 1' : valeur3, 'valeur 2' : valeur4})
p1 = figure(title ='Répartition des sinistres en fonction des surfaces', x_range = modalites, plot_width=600, plot_height=400)
p2 = figure(title ='Répartition des sinistres en fonction des surfaces', x_range = modalites, plot_width=600, plot_height=400)
from bokeh.transform import dodge
abscisses_1 = dodge(field_name = 'x',
value = -0.25,
range = p1.x_range)
abscisses_2 = dodge(field_name = 'x',
value = 0,
range = p1.x_range)
p1.vbar(x = abscisses_1, top = 'valeur 1', width = 0.2, source = source1, color = 'green', legend = 'pas de sinistre')
p1.vbar(x = abscisses_2, top = 'valeur 2', width = 0.2, source = source1, color = "red", legend = "sinistre")
p1.legend.location = "top_left"
p1.legend.orientation = "horizontal"
p1.xgrid.grid_line_color = None
p2.vbar(x = abscisses_1, top = 'valeur 1', width = 0.2, source = source2, color = 'green', legend = 'pas de sinistre')
p2.vbar(x = abscisses_2, top = 'valeur 2', width = 0.2, source = source2, color = "red", legend = "sinistre")
p2.legend.location = "top_right"
p2.legend.orientation = "horizontal"
p2.xgrid.grid_line_color = None
tab1=Panel(child=p1, title='en %')
tab2=Panel(child=p2, title='en valeur absolue')
tabs=Tabs(tabs=[tab1, tab2])
h2 = HoverTool(tooltips = [( "nb bâtiments concernés:", "@top")])
p2.add_tools(h2)
show(tabs)
''' 如果有帮助,这里是 list(tables_2.loc[0]):[2303, 2184, 1909, 1511] 和 list(tables_2.loc[1]):[271, 418, 587, 1046]
【问题讨论】: