I have multiple questions.
Firstly, I'm struggling to get my Bokeh figure with multiple lines to show hover tooltips with values for each line. It shows the same value at all of the lines' tooltips (the value of the closest line's closest data point), instead of the value of each line's points.
See in this image, all tooltips show a value of 1. I expected 5, 3, 1 and not 1, 1, 1:
Below is a MCVE that has the same output:
from bokeh.plotting import figure, show
from bokeh import palettes
from bokeh.models import HoverTool
import itertools
import pandas as pd
dummy = pd.DataFrame({'DT': ['2015-01-01', '2015-01-02', '2015-01-03'], 'Flux': [1, 2, 3], 'Ore': [3, 2, 1], 'Slag': [5, 4, 3]})
dummy.index = pd.to_datetime(dummy['DT'])
dummy.drop('DT', axis=1, inplace=True)
# colour generator
def color_gen():
yield from itertools.cycle(palettes.Category20[len(dummy.columns)])
color = color_gen()
TOOLS = "crosshair,pan,wheel_zoom,box_zoom,zoom_in,zoom_out,reset,save"
p = figure(width=1200, height=600, x_axis_type="datetime", y_axis_label='Kilograms in/out (daily)',
toolbar_location="above", tools=TOOLS, active_scroll="wheel_zoom")
for column in dummy.columns:
x, y = dummy.index.values, dummy[column].values
this_color = next(color)
my_plot = p.line(x, y, legend=column, color=this_color)
p.circle(x, y, legend=column, fill_color="white", line_color=this_color, size=7)
p.add_tools(HoverTool(tooltips=[("Column", " %s" % column),
("Day", "$x{%F}"),
("Weight in/out", "$y{0} kg")],
formatters={'$x': 'datetime'},
mode='vline',
renderers=[my_plot]))
show(p)
Next, I noticed that tooltips overlap if the lines are close to each other. Is it possible to prevent the overlap, or better, create a text block in one of the corners showing the x-location along with all the lines' y's?
Lastly, adding the below code to the custom HoverTool
, I expect it to show only the values of the closest data point instead of interpolated values (as per this question). However, it still interpolates. Any tips on fixing this?