An empty signal pool is created, a hover is added, at the click of a button the data pool is updated. How to avoid the effect of overlapping hovers?!
Test code:
import random
import numpy as np
from bokeh.layouts import column, row
from bokeh.plotting import curdoc, figure
from bokeh.models import ColumnDataSource, Button, HoverTool
POINTS = 1000
PLOT_WIDTH = 1000
PLOT_HEIGHT = 570
signal_src = {}
signal_figure = figure(plot_height=PLOT_HEIGHT, plot_width=PLOT_WIDTH,
tools=["pan,box_zoom,wheel_zoom,save,reset"],
x_axis_label='Time', y_axis_label='Amp')
POOL_LEN = 6
pool_data = []
pool_count = 0
# start making pool for signal
for i in range(POOL_LEN):
color_ = random.choice(('blue', 'red', 'black',
'green', 'yellow', 'orange',
'pink', 'navy'))
name_ = f'stage_{i}'
pool_data.append(ColumnDataSource({'x':[], 'y':[]})) # Add empty data
signal_figure.line(x='x', y='y', source=pool_data[i] ,
name=name_, color=color_)
# end
signal_figure.add_tools(HoverTool(tooltips=[('', "$name"), ('', "($x, $y)")]))
def add_callback():
some_digit = random.randrange(1, 10, step=1)
name = f'signal{some_digit}'
# create new data for signal
signal_src[name] = ColumnDataSource({'x': np.arange(POINTS),
'y': random.randrange(1, 100, step=1) * \
np.sin(2* np.pi * 0.1 * np.arange(POINTS))})
global pool_count
if pool_count < POOL_LEN:
# update data in pool
pool_data[pool_count].data = {'x': signal_src[name].data['x'],
'y': signal_src[name].data['y']}
pool_count += 1
add_btn = Button(label="Add", button_type="default")
add_btn.on_click(add_callback)
curdoc().add_root(row(signal_figure, add_btn))
As I already said - it is working for me with the exact same code. I did not really dig it, but it makes it seem like the workaround is very fickle. And unfortunately, I don’t know any other workaround short from writing custom Bokeh models.
Sorry for the obsession, but on your picture you have 2 plots and one hover, not 2 hovers. Yes, it works well, then cursor in the center of the plots for me too