@nlosacco No sure why it does not work for you, which version of Bokeh are you using? My example below works in 3.4.0.
from bokeh.io import output_file, save
from bokeh.plotting import figure, row, column
import pandas as pd
import numpy as np
from bokeh.models import Legend
output_file('shared_legend_hide.html')
x = list(range(11))
df = pd.DataFrame(data = {
'x' : x,
'y0' : x,
'y1' : [10 - i for i in x],
'y2' : [abs(i - 5) for i in x]})
colors = ['red', 'blue', 'yellow']
def plotter(df, colors, add_legend = False):
legend_it = []
c = figure(width=400, height=300, title=None)
for idx, i in enumerate(['y0', 'y1', 'y2']):
s = c.scatter(
x = 'x', y = i,
marker = 'circle',
source = df, size=10,
color = colors[idx], alpha=0.7,
name = colors[idx]
)
if add_legend:
legend_it.append((i, [s]))
if add_legend:
legend = Legend(items=legend_it)
legend.click_policy="mute"
legend.orientation = 'horizontal'
c.add_layout(legend, 'below')
return c
def link_glyphs(ref_fig, target_fig):
for i in colors:
r = ref_fig.select(name = i)[0]
t = target_fig.select(name = i)[0]
r.js_link('muted', t, 'muted')
c = plotter(df, colors)
k = -0.75
c_sqrt = plotter(np.sqrt(df), colors, add_legend = True)
c_pow = plotter(np.power(df, k), colors)
link_glyphs(c_sqrt, c)
link_glyphs(c_sqrt, c_pow)
save(row(c, c_sqrt, c_pow))