Hi, I’m wondering if there is a way to get a plot legend to turn on/off its correspondingly colored polygons when they all belong to the same Patches object.
See my super simple working example below:
from bokeh.io import show
from bokeh.models import ColumnDataSource,CustomJS, widgets, LinearColorMapper
from bokeh.palettes import RdBu6
from bokeh.plotting import figure
from bokeh.layouts import layout
import numpy as np
source = ColumnDataSource(dict(
xs=[[1,2,2], [1,2,2], [3,4,4], [3,4,4]],
ys=[[3,3,4], [1,1,2], [3,3,4], [1,1,2]],
s1=[0, 50, 75, 50],
label_1=['Blue', 'Orangy', 'Red', 'Orangy'],
))
cmap1 = LinearColorMapper(palette='RdBu6', low = 0, high = 75)
p = figure(x_range=(0, 7), y_range=(0, 5), plot_height=300)
patches = p.patches( xs='xs', ys='ys', fill_color={'field':'s1','transform':cmap1}
, legend_field='label_1', source=source)
p.legend.click_policy='hide'
show(p)
The legend.click_policy lets me hide the entire patches object, but I’d like to toggle individual legend entries. I’ve tried implementing a checkbox JS callback as outlined here: python - Bokeh Interactive legend hide multiple glyphs - Stack Overflow
However, I’m running into snags because the setup above uses methods that exist for the Bar object but not for the Patches object. Before I go diving into this approach but for Patches, not Bars, I’m wondering if this is the right approach or there’s something else entirely I can do. My only caveat is that I really can’t break up my patch objects into multiple glyphs - my real life version (not simplified example) is far too big to do that.
Any help greatly appreciated