У меня есть следующий код:
from bokeh.models import HoverTool, ColumnDataSource
from bokeh.plotting import figure, output_file, show
if __name__ == '__main__':
year = [1960, 1970, 1980, 1990, 2000, 2010]
pop_pakistan = [44.91, 58.09, 78.07, 107.7, 138.5, 170.6]
pop_india = [449.48, 553.57, 696.783, 870.133, 1000.4, 1309.1]
output_file('line.html', mode='inline')
plot = figure(title='Population Graph of India and Pakistan', x_axis_label='Year',
y_axis_label='Population in million')
source1 = ColumnDataSource(data=dict(
year=year,
population=[pop_pakistan, pop_india],
))
print(source1.data)
hover = HoverTool()
hover.tooltips = """
<div style=padding=5px>Data</div>
"""
plot.add_tools(hover)
plot.line(year, pop_pakistan, line_width=2, line_color='green', legend='Pakistan')
plot.circle(year, pop_pakistan, fill_color="green", line_color='green', size=8)
plot.line(year, pop_india, line_width=2, line_color='orange', legend='India')
plot.circle(year, pop_india, fill_color="orange", line_color='orange', size=8)
show(plot)
Я хочу показать данные при наведении курсора.Я получаю следующее предупреждение
BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('population', 2), ('year', 6)
Как использовать Hovertool для нескольких осей Y?
Спасибо
Обновление
Основываясь на ответе @bigreddot, я внес следующие изменения:
plot.line('year', 'pop_pakistan', line_width=2, line_color='green', legend='Pakistan', source=source)
plot.circle('year', 'pop_pakistan', fill_color="green", line_color='green', size=8, source=source)
plot.line('year', 'pop_india', line_width=2, line_color='orange', legend='India', source=source)
plot.circle('year', 'pop_india', fill_color="orange", line_color='orange', size=8, source=source)
show(plot)
Но я не могу показать соответствующие данные при наведении курсора для соответствующей страны.